Hacker News new | past | comments | ask | show | jobs | submit login

In CPython, calling super() has about the same cost as calling any other builtin like len() or int(). The MRO itself is precomputed and stored in inst.__class__.__mro__.

Contrasting dict.__setitem__ with super().__setitem__, the latter adds one function call. In addition, both forms require a builtin lookup and an attribute lookup.

In PyPy, much of the overhead of builtin lookups, function calls, and attribute lookups is automatically optimized away.




Unfortunately on PyPy super is less efficient than refering directly to the parent classes method, however it's fixable (and will be fixed).


Do you have some sort of timing measure?


No, I haven't timed it myself, I just know how it's implemented and what code we're generating internally.

Edit: To be clear I would not advocate not using super() on account of this, as I said it'll eventually be fixed.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: