Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update_one_slot() does not inherit sq_contains and mp_subscript if they are explictly declared #83935

Closed
Marco-Sulla mannequin opened this issue Feb 25, 2020 · 2 comments
Labels
3.9 only security fixes performance Performance or resource usage topic-C-API

Comments

@Marco-Sulla
Copy link
Mannequin

Marco-Sulla mannequin commented Feb 25, 2020

BPO 39754
Nosy @benjaminp, @Marco-Sulla

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2020-02-26.19:09:15.608>
created_at = <Date 2020-02-25.20:17:09.547>
labels = ['expert-C-API', '3.9', 'performance']
title = 'update_one_slot() does not inherit sq_contains and mp_subscript if they are explictly declared'
updated_at = <Date 2020-02-26.19:09:15.607>
user = 'https://github.com/Marco-Sulla'

bugs.python.org fields:

activity = <Date 2020-02-26.19:09:15.607>
actor = 'Marco Sulla'
assignee = 'none'
closed = True
closed_date = <Date 2020-02-26.19:09:15.608>
closer = 'Marco Sulla'
components = ['C API']
creation = <Date 2020-02-25.20:17:09.547>
creator = 'Marco Sulla'
dependencies = []
files = []
hgrepos = []
issue_num = 39754
keywords = []
message_count = 2.0
messages = ['362662', '362677']
nosy_count = 2.0
nosy_names = ['benjamin.peterson', 'Marco Sulla']
pr_nums = []
priority = 'normal'
resolution = 'duplicate'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'performance'
url = 'https://bugs.python.org/issue39754'
versions = ['Python 3.9']

@Marco-Sulla
Copy link
Mannequin Author

Marco-Sulla mannequin commented Feb 25, 2020

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: https://stackoverflow.com/a/59914459/1763602

@Marco-Sulla Marco-Sulla mannequin added 3.9 only security fixes topic-C-API performance Performance or resource usage labels Feb 25, 2020
@benjaminp
Copy link
Contributor

See also bpo-34396.

@Marco-Sulla Marco-Sulla mannequin closed this as completed Feb 26, 2020
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.9 only security fixes performance Performance or resource usage topic-C-API
Projects
None yet
Development

No branches or pull requests

1 participant