{{ message }}
perf: avoid scanning the type cache on type mutation - #8628
Draft
moreal wants to merge 2 commits into
Draft
Conversation
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Contributor
Assisted-by: Codex:gpt-5.6-sol
Assisted-by: Codex:gpt-5.6-sol
moreal
force-pushed
the
perf/type-cache-invalidation
branch
from
September 2, 2026 17:22
f2b1f39 to
0d1e846
Compare
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
Type mutation previously invalidated method-cache entries by scanning all 4,096 slots for the type's old version tag. This made every cached type mutation pay for a full-cache scan.
This change invalidates the type by setting its version tag to zero and leaves the old cache entry in place. Type version tags are monotonic and never reused; once the counter is exhausted, new tag assignment remains disabled. Cache readers accept an entry only when its version and interned name match the type's current version under the existing sequence-lock protocol, so an entry for an invalidated version is unreachable.
Cached values are already marked as published and use QSBR-delayed allocation reclamation, which lets an in-flight reader that observed the old version finish its conditional incref safely. The existing whole-cache clear still nulls every borrowed pointer before cyclic GC breaks type reference cycles.
This also adds a microbenchmark for repeated cached lookup followed by type mutation, plus focused tests for version reachability and concurrent cache readers.
Performance
benches/microbenchmarks/type_cache_invalidation.pycompares the benchmark-only commit with the invalidation change:AI assistance
Codex (
gpt-5.6-sol) assisted extensively with the implementation, tests, benchmark setup and analysis, automated validation, code review, and drafting this PR description.