Skip to content

gh-141510: Update specializer to support frozendict with BINARY_SUBSCR#144911

Open
corona10 wants to merge 13 commits intopython:mainfrom
corona10:gh-141510-specializer
Open

gh-141510: Update specializer to support frozendict with BINARY_SUBSCR#144911
corona10 wants to merge 13 commits intopython:mainfrom
corona10:gh-141510-specializer

Conversation

@corona10
Copy link
Member

@corona10 corona10 commented Feb 17, 2026

We need to register frozendict for support in the specializer.

Since frozendict is only introduced in Python 3.15, it is not yet widely used. However, it is thread safe for many operations, including CALL_LEN and BINARY_OP_SUBSCR. It could also be optimized more aggressively in the JIT using KNOWN_CLASS optimizations in the pipeline.

This is just part of a draft PR. I am also happy to make _BINARY_OP_SUBSCR_FROZEN_DICT part of _BINARY_OP_SUBSCR_DICT, depending on what the JIT team prefers.

Without this PR, frozendict would be at a performance disadvantage, even though it is intended to be a first-class citizen alongside dict.

@corona10 corona10 changed the title gh-141510: Update specialzier to support frozendict with BINARY_SUBSCR gh-141510: Update specializer to support frozendict with BINARY_SUBSCR Feb 17, 2026
@Sacul0457
Copy link
Contributor

Would it be good if _GUARD_NOS_FROZEN_DICT was added to optimizer_bytecodes.c so that it could be removed by the optimizer if the type is known?

@Fidget-Spinner
Copy link
Member

I think it's better to focus on getting the specializer correct in this PR for now. We can leave the JIT for another PR.

@corona10
Copy link
Member Author

@Sacul0457 I think that we have to, I will update the PR or handle it at the seperate PR, but it needs feedback from JIT team first :)

@Fidget-Spinner
Copy link
Member

This needs tests in test_opcache for the specialization success and failure case.

@corona10
Copy link
Member Author

Once the PR is merged, I am also going to work on CONTAINS_OP_FROZENDICT too.

@corona10 corona10 requested a review from vstinner February 17, 2026 14:53
Co-authored-by: Victor Stinner <vstinner@python.org>
@corona10 corona10 requested a review from vstinner February 17, 2026 15:31
@corona10
Copy link
Member Author

corona10 commented Feb 17, 2026

@Fidget-Spinner Now whole unit tests are passed.

@corona10 corona10 requested a review from vstinner February 17, 2026 21:28
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@markshannon
Copy link
Member

markshannon commented Feb 18, 2026

Do you have any evidence that this will improve performance?

Opcodes are a limited resource, and since no one is using frozen dicts yet, this is just going to slow down the interpreter by adding bulk.

Relaxing the guard in BINARY_OP_SUBSCR_DICT to check for any dict, and removing the redundant check in PyDict_GetItemRef would achieve your goal without lots of extra code or any slow down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants