Title: update_one_slot() does not inherit sq_contains and mp_subscript if they are explictly declared
Type: performance Stage: resolved
Components: C API Versions: Python 3.9
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: Marco Sulla, benjamin.peterson
Priority: normal Keywords:

Created on 2020-02-25 20:17 by Marco Sulla, last changed 2020-02-26 19:09 by Marco Sulla. This issue is now closed.

Messages (2)
msg362662 - (view) Author: Marco Sulla (Marco Sulla) * Date: 2020-02-25 20:17
I noticed that `__contains__()` and `__getitem__()` of subclasses of `dict` are much slower. I asked why on StackOverflow, and an user seemed to find the reason.

The problem for him/her is that `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, I suppose.

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:
msg362677 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2020-02-26 02:17
See also #34396.
Date User Action Args
2020-02-26 19:09:15Marco Sullasetstatus: open -> closed
resolution: duplicate
stage: resolved
2020-02-26 02:17:47benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg362677
2020-02-25 20:17:09Marco Sullacreate