Perf: drop First/Last wrappers in AppendingBlockImpl#27
Draft
Perf: drop First/Last wrappers in AppendingBlockImpl#27
Conversation
…+ discriminator AppendingBlockImpl was wrapping every appended SimpleNode in a one-field First/Last wrapper class before storing on the instance. Each wrapper escapes (stored in this.first / this.last), so V8 can't elide the allocation. For a 5000-row render, didAppendNode runs at least once per row (often more for multi-node elements), allocating a wrapper each time — meaningful GC pressure for a no-op indirection. Store the raw SimpleNode (or Bounds) directly, with a boolean discriminator per slot (_firstIsBounds / _lastIsBounds) that firstNode() and lastNode() check before returning. Saves one allocation per append without changing the interface exposed to callers.
📊 Package size report 0.01%↑
🤖 This report was automatically generated by pkg-size-action |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Exploration PR — change from NVP's emberjs/ember.js#21221.
Drop
First/Lastwrapper classes inAppendingBlockImpl; store rawSimpleNode | Bounds+ discriminator booleans instead.Isolated microbench
bin/first-last-wrappers.bench.mjs:didAppendNode5000 nodes (Krausest shallow)didAppendNode20000 nodes (deep template)Allocation: old 12–850 kB/iter → new ~0 B (V8 fully elides the wrapper allocs in the new form; they were real escapes in the old).
Krausest (tracerbench)
All 23 phases show no difference at both fidelities. Saved to
.bench/b3-firstlast-wrappers.jsonand.bench/c-firstlast-80fid.json.Why the gap between micro and Krausest
Isolated: −82 % on 5000 appends. Krausest: null.
Krausest's per-render wrapper cost is ~17 µs (5000 rows × ~3.5 µs/row), which is 0.8 % of the ~2200 ms bench total — below the tracerbench noise floor. The mechanism is real; Krausest just doesn't exercise enough allocation pressure at the per-render level to see it. A long-running app or a deeper template might.
Verdict
Microbench-positive, Krausest null. Real isolated win, no end-to-end impact at Krausest scale. Whether it's worth merging is a judgment call about allocation pressure in real apps vs the small-but-nonzero risk of hidden-class shape change (new form has 4 fields + 2 booleans vs old's 2 wrapper fields). Closing as documented null at Krausest scale.