[issue34396] Certain methods that heap allocated subtypes inherit suffer a 50-80% performance penalty

Marco Sulla report at bugs.python.org
Wed Feb 26 14:11:37 EST 2020


Marco Sulla <launchpad.net at marco.sulla.e4ward.com> added the comment:

I asked why on StackOverflow, and an user seemed to find the reason. The problem for him/her is in `update_one_slot()`. 

`dict` implements directly `__contains__()` and `__getitem__()`. Usually, `sq_contains` and `mp_subscript` are wrapped to implement `__contains__()` and `__getitem__()`, but this way `dict` is a little faster.

The problem is that `update_one_slot()` searches for the wrappers. If it does not find them, it does not inherit the `__contains__()` and `__getitem__()` of the class, but create a `__contains__()` and `__getitem__()` functions that do an MRO search and call the superclass method. This is why `__contains__()` and `__getitem__()` of `dict` subclasses are slower.


Is it possible to modify `update_one_slot()` so that, if no wrapper is found, the explicit implementation is inherited?

SO answer: https://stackoverflow.com/a/59914459/1763602

----------
components: +C API -Interpreter Core
nosy: +Marco Sulla
versions: +Python 3.9 -Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34396>
_______________________________________


More information about the Python-bugs-list mailing list