gh-155962: Specialize LOAD_ATTR after replacing an instance's __dict__ - #155963
Open
koxudaxi wants to merge 3 commits into
Open
gh-155962: Specialize LOAD_ATTR after replacing an instance's __dict__#155963koxudaxi wants to merge 3 commits into
__dict__#155963koxudaxi wants to merge 3 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replacing an instance's
__dict__preventsLOAD_ATTRfrom specializing on Python 3.14 and main. The same case specializes toLOAD_ATTR_WITH_HINTon Python 3.13.instance_has_key()used shared keys whenever the type supported inline values, even after replacing an instance's__dict__had invalidated its inline values. Check the per-instance state and use the managed dictionary instead. General-key dictionaries remain unsupported by the hint opcodes.This affects Pydantic v2 because pydantic-core installs validated fields by replacing the model's
__dict__.Benchmark
Fresh-process datamodel-code-generator CLI generation using a 500-definition JSON Schema, Pydantic v2 output, the built-in formatter, and a temporary output file:
This is a 26.8 ms (7.6%) reduction. The results are medians from 11 alternating-order samples on macOS arm64.
Tests
Tests cover replacement dictionaries with stale shared keys, unsupported general-key dictionaries, and concurrent dictionary replacement.
Fixes #155962
__dict__#155962