-
-
Notifications
You must be signed in to change notification settings - Fork 158
perf(runtime): 2-way set-associative write stub — computed-key write loop now beats node (−50%) #8977
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
perf(runtime): 2-way set-associative write stub — computed-key write loop now beats node (−50%) #8977
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
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,25 @@ | ||
| The megamorphic write stub is 2-way set-associative, and the computed-key | ||
| **write loop is now faster than node**: 40 → 20 ms against node's 24 ms on the | ||
| same host (−50%), with the combined overwrite loop 70 → 48 ms (−31%). | ||
|
|
||
| A direct-mapped table cannot hold a colliding pair *at all*. The two keys evict | ||
| each other on every rotation through the key set, so both miss forever and | ||
| neither ever stabilises — the miss is not probabilistic, it is permanent. On | ||
| the 500-key write loop that left ~87k of 600k writes falling through every | ||
| cache into the full `[[Set]]` walk, which the call graph put at **11.9% of the | ||
| program**, essentially all of it (10.7%) inside `js_put_value_set`. | ||
|
|
||
| The cause was invisible in a profile and only showed up in counters: probes | ||
| were missing with the RIGHT shape token and the WRONG key in the way. Dumping | ||
| the colliding pairs named them outright — `"k10"`/`"k115"` and `"k11"`/`"k125"`, | ||
| landing on indices 3885 and 2220. | ||
|
|
||
| Two ways per bucket at the same total capacity (2048 × 2 rather than 4096 × 1), | ||
| so the table does not grow. A sweep of the working set puts the worst bucket at | ||
| exactly two, so two ways absorb the collisions that exist rather than merely | ||
| reducing them. Insert refreshes a resident key, then fills an empty way, and | ||
| only otherwise evicts, shifting way 0 down so the most recently primed key | ||
| survives. | ||
|
|
||
| Suite: 2779 passed, 0 failed. Computed-key differential output 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
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
Maintain the stated LRU order.
write_stub_probeleaves a hit in its current way, andwrite_stub_insertrefreshes a matching entry in place. IfAis in way 0 andBis in way 1, a hit or refresh ofBfollowed by insertion ofCshifts way 0 into way 1 and evictsB. Promote the matched entry to way 0, or otherwise update recency on both paths, before inserting or evicting.Suggested promotion helper
Also applies to: 709-714, 722-725
🤖 Prompt for AI Agents