-
-
Notifications
You must be signed in to change notification settings - Fork 159
perf(json): right-size tape object spill buffers #8016
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:perf/7267-json-tape-inline-slots
Aug 13, 2026
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,21 @@ | ||
| ### perf(json): right-size tape-materialized object spill buffers (#7267) | ||
|
|
||
| JSON tape materialization previously allocated every object at the two-slot | ||
| inline floor, then let the first overflowing property create a general-purpose | ||
| array with 16 slots of growth headroom. Five-field records therefore carried a | ||
| 16-slot side allocation even though the tape already knew their final width. | ||
|
|
||
| Both the recursive lazy materializer and the iterative deep-input materializer | ||
| now reserve an exact-width spill buffer before storing fields. The recursive | ||
| path counts only the current object's keys by hopping across nested container | ||
| links; the iterative path reuses the key count it has already collected. The | ||
| primary object deliberately remains at `INLINE_SLOT_FLOOR`: sizing its inline | ||
| allocation to every key was benchmarked in #7267 and regressed the named field | ||
| access workload. | ||
|
|
||
| On `benchmarks/json_polyglot/bench_field_access.ts`, eight interleaved | ||
| `perry-dev` runs with `PERRY_NO_AUTO_OPTIMIZE=1` reduced median time from | ||
| 1266.5 ms to 1138.5 ms (-10.1%) and peak RSS from 309.3 MiB to 294.3 MiB | ||
| (-4.8%), with identical checksums. A direct-parser control was unchanged | ||
| (934.5 ms vs 935.5 ms median), isolating the improvement to tape-backed object | ||
| materialization. |
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
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
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
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.
🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win
Root and reload
objectafter spill reservation.reserve_object_spillcan allocateObjectMetaand the spill array. A moving collection can relocateobjectduring this call. The callee reloads only its local pointer. Lines 47-53 still use the caller's stale pointer.Root
objectinfinish_frame, callreserve_object_spillthrough the rooted pointer, and reload it before field insertion and return. Add a regression that forces collection during this reservation path.Proposed fix
let field_count = u32::try_from(keys.len()).ok()?; let object = crate::object::js_object_alloc(0, 0); - crate::object::reserve_object_spill(object as usize, field_count); + let scope = crate::gc::RuntimeHandleScope::new(); + let object_handle = scope.root_raw_mut_ptr(object); + crate::object::reserve_object_spill( + object_handle.get_raw_mut_ptr::<crate::object::ObjectHeader>() as usize, + field_count, + ); + let object = object_handle.get_raw_mut_ptr::<crate::object::ObjectHeader>(); for (key, value) in keys.into_iter().zip(values) {Based on learnings: raw Rust pointer locals are not GC roots, and callers must reload them after GC-capable operations.
📝 Committable suggestion
🤖 Prompt for AI Agents
Source: Learnings