{{ message }}
perf: use interned name in generic_getattr_opt#8129
Open
sharifhsn wants to merge 1 commit into
Open
Conversation
… getattr generic_getattr_opt looked up the instance dict by name_str.as_wtf8() -- the &Wtf8 content, whose DictKey::key_hash recomputes the SipHash from the raw bytes on every attribute access. Look it up by name_str (the &Py<PyStr>) instead: its DictKey returns the hash PyStr already caches, and adds a pointer-equality fast path for the key compare. (generic_setattr already passed the PyStr, so writes were never affected.) Free -- no memory added; the hash cache already exists. Benchmarks (interleaved A/B vs main, median): attribute-read loop -17.3%, pystone -3.0%, OOP method loop -7.9%; neutral on non-attribute code. Verified: 12 attribute/descriptor/class/dataclass test modules pass; clippy clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Assisted-by: Claude:claude-opus-4
Contributor
youknowone
requested changes
Jun 22, 2026
youknowone
left a comment
Member
There was a problem hiding this comment.
the patch makes sense.
please check our AI policy and check the checkbox
Member
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.

Summary
generic_getattr_optlooked up the instance dict byname_str.as_wtf8(), which required recomputing the SipHash from the raw bytes on every attribute access. Nowname_str: &Py<PyStr>implementsDictKey, which returns the hashPyStralready caches, and adds a pointer-equality fast path for the key compare, which is much faster than using.as_wtf8().Benchmarks vs main, median: attribute-read loop -17.3%, pystone -3.0%, OOP method loop -7.9%; neutral on non-attribute code.
Assisted-by: Claude:claude-opus-4-8
Summary by CodeRabbit