Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

GH-89987: Shrink theBINARY_SUBSCR caches#103022

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

brandtbucher
Copy link
Member

@brandtbucherbrandtbucher commentedMar 25, 2023
edited by bedevere-bot
Loading

BINARY_SUBSCR has 3 cache entries that are only used byBINARY_SUBSCR_GETITEM (a type version and a function version). However, we don't really need to store all of this information per call-site... we can just keep the function version on the type (next to the cached method) and clear the cached method whenever the type is modified.

Besides the savings in code size, this has a couple of other minor benefits:

  • AnyBINARY_SUBSCR_GETITEM site can work withany heap type defining__getitem__, provided it's already been cached at least once somewhere.
  • We can specialize for more than 65k function versions.

Performance isneutral.

@markshannon
Copy link
Member

markshannon commentedMar 28, 2023
edited
Loading

I'm a bit concerned aboutABA errors.
For example:

  1. Site X is specialized for some version of class C and C.getitem.
  2. Then C.getitem is modified
  3. Site Y is specialized, setting the cached version to the new function.
  4. Now site X runs again.

Is this OK?

I think it is, but it requires a different contract between the specializer, the specialized code and the class's cache, than we had before.

This contract will need to be clearly documented.
Does this seem correct:

  • If the_specialization_cache.getitem field is non-NULL, then the value it holds is whatPyType_Lookup(cls, "__getitem__") would return.
  • If_specialization_cache.getitem is NULL, thegetitem_version field is meaningless.
  • If the_specialization_cache.getitem field is non-NULLand_specialization_cache.getitem_version == _specialization_cache.getitem->func_version then_specialization_cache.getitem is a Python function that can be called with two positional arguments and no keyword arguments, and has neither*args nor**kwargs.

@brandtbucher
Copy link
MemberAuthor

Yes, that's correct. I'll document this clearly in a comment.

@brandtbucherbrandtbucher merged commit121057a intopython:mainMar 29, 2023
warsaw pushed a commit to warsaw/cpython that referenced this pull requestApr 11, 2023
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@markshannonmarkshannonAwaiting requested review from markshannonmarkshannon is a code owner

Assignees

@brandtbucherbrandtbucher

Labels
performancePerformance or resource usage
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@brandtbucher@markshannon@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp