-
-
Notifications
You must be signed in to change notification settings - Fork 158
gc(shapes) phase 3: make the transition cache's target edge weak, and reap dead targets #8900
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
proggeramlug
merged 1 commit into
PerryTS:main
from
proggeramlug:arch-phase3-transition-edges
Aug 28, 2026
+113
−1
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| Stopped the transition cache from keeping shapes alive: its `next_keys` edge is | ||
| now weak, and an entry whose target died is reaped. | ||
|
|
||
| `scan_transition_cache_roots_mut` visited `next_keys` with `visit_usize_slot`, | ||
| which **marks**. With 16384 slots the cache could therefore pin 16384 keys | ||
| arrays — and, through them, their shape descriptors — whether or not any live | ||
| object still had that shape. | ||
|
|
||
| That is a direct contributor to the shape table growing without bound between | ||
| full collections, measured at **786,205 descriptors on a workload holding under | ||
| 400 live objects**, with the shape scanner's cost tracking it (3.6 ms → 490 ms | ||
| per call). | ||
|
|
||
| A transition entry is a pure cache: it answers *"adding key k to shape S yields | ||
| shape T"*. If nothing has shape T any more, the answer is worthless, so pinning | ||
| T's keys array to keep it answerable is backwards. `key_ptr` in the same entry | ||
| was already weak and metadata-only for exactly this reason; this makes the pair | ||
| consistent. | ||
|
|
||
| Both halves move together, and have to: | ||
|
|
||
| * `scan_transition_cache_roots_mut` now visits `next_keys` rewrite-only, so a | ||
| surviving target's address stays correct but a dead one is not resurrected; | ||
| * `prune_dead_transition_cache_entries` gains `is_dead_owner(entry.next_keys)`, | ||
| so an entry whose target did not survive is dropped rather than left dangling. | ||
|
|
||
| Weakening the edge without the reaping half would leave a stale pointer in the | ||
| cache. | ||
|
|
||
| The regression test seeds an entry with a **live** `prev_shape_id` on purpose. | ||
| An earlier version used `prev_shape_id = 0`, which the prune's pre-existing | ||
| `shape_descriptor_by_id(..).is_none()` clause already treats as dead — so it | ||
| passed with the new clause deleted and proved nothing. Sabotage-checked in its | ||
| final form: removing `is_dead_owner(entry.next_keys)` fails it. | ||
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Keep development history out of the changelog entry.
The release note should describe the shipped weak
next_keysedge and dead-entry pruning. Remove theprev_shape_idtest-history and sabotage details from this fragment. Keep those details in the regression test or PR description so the assembled changelog remains one coherent release-note entry.Based on learnings: Perry changelog fragments must describe final shipped behavior as one coherent release-note entry, without development-slice narratives.
🤖 Prompt for AI Agents
Source: Learnings