-
-
Notifications
You must be signed in to change notification settings - Fork 158
bench: populated-object delete churn — the ~200× gap, and why a memo cannot fix it #8946
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:bench-populated-delete
Aug 28, 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,38 @@ | ||
| // Benchmark: delete/re-add churn on a POPULATED object — the cache/dictionary | ||
| // pattern (`delete obj[k]; obj[k] = v` with k rotating over resident keys). | ||
| // | ||
| // Measured 2026-08-29 (16-core Linux host, node v26.8.1, N = 200_000, | ||
| // 500 resident keys): | ||
| // | ||
| // node 37 ms | ||
| // perry ~8_000 ms (~200x) | ||
| // | ||
| // This is EIGHT TIMES worse than the 0<->1-key delete oscillation | ||
| // (`bench_dynamic_property_keys`' delete loop, ~25x after #8936), because the | ||
| // churn cost scales with the RESIDENT key count: every iteration pays a | ||
| // 500-element keys-array clone on the delete, a second clone on the re-add | ||
| // (appending to a shared array), two layout rebuilds, two shape-descriptor | ||
| // mints (with `ShapeFacts` hashing and reverse-index maintenance), and a | ||
| // 500-slot value shift. O(resident keys) per delete, with large constants. | ||
| // | ||
| // A delete-transition memo (V8-style back-transitions keyed on the keys | ||
| // array's ADDRESS) was built and measured against this benchmark: it was a | ||
| // WASH, twice, in drift-cancelling interleaved A/B pairs — with rotating keys | ||
| // each delete+re-add changes the shape, so the next delete is a fresh | ||
| // (shape, key) pair and address-keyed memoisation never converges. It was | ||
| // deleted rather than shipped. The structural fix needs a content-stable | ||
| // shape identity (facts independent of the keys array's address), so that | ||
| // equal key-sets reuse one canonical shape regardless of which clone produced | ||
| // them — that is a shape-interning change, not a cache. | ||
| const o: Record<string, number> = {}; | ||
| for (let i = 0; i < 500; i++) o["k" + i] = i; | ||
| let s = 0; | ||
| const N = 200000; | ||
| const t = Date.now(); | ||
| for (let i = 0; i < N; i++) { | ||
| const k = "k" + (i % 500); | ||
| delete o[k]; | ||
| o[k] = i; | ||
| s += o[k]; | ||
| } | ||
| console.log("popdel_ms=" + (Date.now() - t) + " chk=" + (s % 7)); | ||
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
Correct the measurement date before merging.
The header says
Measured 2026-08-29, but the current date is August 28, 2026. This is a future-dated result. Replace it with the actual run date, or remove the measurements until the benchmark runs.🤖 Prompt for AI Agents