-
-
Notifications
You must be signed in to change notification settings - Fork 161
perf(runtime): stop re-deriving the receiver on every array push (−74%) #10414
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
24457fa
perf(runtime): stop re-deriving the receiver on every array push
27eb7f9
docs: changelog fragment for #10414
9d4041f
perf(runtime): drop the provably-no-op layout note from the raw-f64 push
0b657c6
docs: changelog fragment for the layout-note elision
38743ac
fix(runtime): delete the array push wrapper that lost its last caller
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,14 @@ | ||
| Drop the provably-no-op layout note from the raw-f64 array push. | ||
| `layout_note_slot` was 15.0% of a push/pop loop, 96 of its 109 samples from the | ||
| single call in `array_numeric_raw_f64_push_inbounds`, where the caller has | ||
| already proved the value is a plain number. The mask work is then a no-op in | ||
| every layout state the receiver can be in — the same argument already written | ||
| out for the codegen-side elision on `array_store_needs_layout_note`'s object | ||
| twin. The #7480 element-shape invariant is kept, through the resolved-flags | ||
| entry so it reads the header the caller already holds. | ||
|
|
||
| Validated on the shape that would expose a mistake: array slots filled with | ||
| POINTERS, popped, then refilled with plain numbers, with a retained live graph. | ||
| Three seeds under from-space protection, evacuation verification and | ||
| PERRY_GC_FROMSPACE_SCAN_ABORT=1 each ran ~270,000 copying minors and ~33,700 | ||
| from-space scans with dangling=0 and missing_rewrites=0, 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| Stop re-deriving the receiver on every `Array.prototype.push`. A hot | ||
| `for (…) { a.push(v); a.pop(); }` loop cost 1,350 instructions per push+pop | ||
| pair, and a symbol-resolved profile showed more than half of that was not the | ||
| append but the append re-asking questions about a receiver it had already | ||
| resolved, once per helper in the chain. 1,350.6 -> 432.0, **-68.0%**, with | ||
| nothing inlined and nothing cached. | ||
|
|
||
| Four removals. `typed_feedback::numeric_array_push_guard` probed the property | ||
| descriptor of `"length"` on every push — the heaviest frame in the loop at | ||
| 16.5% of samples — although the flag test three lines above had already | ||
| rejected every receiver that could make it answer true (a non-writable | ||
| `length` always marks `OBJ_FLAG_ARRAY_DESCRIPTORS`). | ||
| `js_array_numeric_push_f64_unboxed` re-ran `clean_arr_ptr` three more times by | ||
| asking `array_is_sealed_or_no_extend`, `array_is_frozen` and | ||
| `guard_writable_length` in sequence, each of which goes through the | ||
| non-resolved `array_object_flags`; that function alone was 24.0% of the loop. | ||
| The append chain resolved twice more, and the exotic and numeric-layout checks | ||
| once each. `js_array_pop_f64` already carried this exact fix — `push` never got | ||
| it. | ||
|
|
||
| Also fixes a parity bug the new fixture found: | ||
| `Object.preventExtensions(a); a.push(1)` silently kept the old length where | ||
| node throws. The dense append answers `SEALED | NO_EXTEND` with a bare | ||
| `return arr`, which is correct for the internal CreateDataProperty-style append | ||
| that builds fresh result arrays and wrong for user `push`; the observable entry | ||
| now throws, with node's wording. `Object.seal` had masked it by routing down | ||
| the exotic path for an unrelated reason. | ||
|
|
||
| Known divergence left: frozen `pop` still reports "Cannot mutate a frozen | ||
| array" rather than node's "Cannot delete property 'N' of [object Array]". |
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.
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 50369
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 50369
Resolve the array before reading the push error index.
array_is_frozenfollows forwarding pointers internally, but it does not updatearr_ptrorarr. Array growth stores the replacement pointer in the old payload, replacing the oldlengthandcapacitywords. Both nativepushpaths can therefore pass forwarding-pointer payload bits tothrow_non_extensible_array_push.Resolve
arr_ptrandarrbefore the frozen check, then use the resolved pointers for thelengthread and subsequent operations at both sites.🤖 Prompt for AI Agents