Repository navigation
perf(runtime): stop hashing a hash in the shape key index; memcpy the delete key clone #9000
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,28 @@ | ||
| Two costs removed from the populated-delete path — perry's worst object-model | ||
| gap against node (`bench_populated_delete.ts`, ~280×). | ||
|
|
||
| **1. The shape key index no longer hashes a hash.** `ShapeIndex::slots` was a | ||
| std `HashMap<u64, Vec<u32>>` whose key is ALREADY an FNV-1a content hash, so | ||
| every probe ran SipHash over it — no added distribution, real time. | ||
| `hash_one::<&usize>` plus `sip::Hasher::write` were **14.7% of self time** in | ||
| that benchmark, second only to `shape_slot_lookup`, which is what performs the | ||
| probes. It now uses the `PtrHasher` the runtime's other id-keyed registries | ||
| already use. | ||
|
|
||
| **2. The keys-array clone is a memcpy.** Each delete allocates a fresh keys | ||
| array and previously copied the surviving keys one `f64` at a time; it is now | ||
| two `copy_nonoverlapping` runs. Safe by the code's own existing argument: the | ||
| destination is a freshly allocated, still-unpublished array whose layout is | ||
| rebuilt before publish — which is why the per-element writes carried no GC | ||
| barrier either — and the two allocations cannot overlap. | ||
|
|
||
| Interleaved A/B, min-of-15 at quiet load: 5938 → 5847 ms (−1.5% min, −2.2% | ||
| mean). Smaller than the profile share suggests, because the delete path is | ||
| dominated by allocator and page churn (`clear_page_erms` 5.6%, `mi_free` 4.2%, | ||
| `RawVecInner::finish_grow` 2.9%) rather than by hashing — the index is rebuilt | ||
| per delete, and each of its ~500 buckets is a separate `Vec<u32>`. That is the | ||
| next target and is untouched here. | ||
|
|
||
| Suite 2787 passed, 0 failed, no warnings. Adversarial property differential | ||
| (delete-then-reread, accessor over a cached slot, prototype fallback, freeze, | ||
| key-order shapes, overflow slots) is byte-identical to node. |
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.
🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 50370
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 35732
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 8081
Preserve the existing capacity reservation.
new_ptr_hash_map()usesHashMap::with_hasher(PtrHasher)without reserving capacity. After a delete, the nextindex_rangerebuild can therefore grow and rehashslotsas it inserts entries. Add a capacity-awarePtrHashMapconstructor and passkey_count.🤖 Prompt for AI Agents