Repository navigation
perf(runtime): make merged refs ~24-34% faster to mount and unmount - #104
Merged
Merged
Conversation
Track pending cleanups as flat [kind, payload] entries in one array instead of allocating a closure per ref on every mount. Callback order, cleanup order, .current/.value assignment, and thrown-callback or thrown-cleanup abort behavior are unchanged.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
merged_ref_prop allocated one closure per ref per mount through apply_ref_value. Collect cleanups as flat [kind, payload] pairs instead, preserving mount order, cleanup order, and thrown-error behavior.
trueadm
approved these changes
Sep 13, 2026
Merged
This was referenced Sep 14, 2026
This was referenced Sep 25, 2026
This branch was successfully deployed
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.
Summary
The two helpers the compilers emit when an element's refs need merging —
mergeRefs(explicitrefplus a spread that may carry one) andmerge_ref_props(refs collected during spread normalization) — now mount and unmount roughly 24–34% faster. Both previously allocated one closure per ref per mount to remember how to unmount it; they now record flat[kind, payload]pairs and dispatch on the kind tag, so a mount allocates one array and one closure total instead of one array plus N closures. Semantics are unchanged: same mount order, same cleanup order, same exception behavior.Measurements
Paired-sample benchmark (fresh Node process per sample, alternating baseline/candidate launch order, median paired relative delta; Node v22.22.2, macOS arm64). Acceptance required ≥9 pairs, identical semantic checksums, raw and median ≥ 5%, and
2×MAD < median.merge_refs(4 refs + spread-carried)merge_refs2(2 refs, common shape)merge_props2(2 refs viamerge_ref_props)merge_props4(4 mixed refs viamerge_ref_props)Controls stayed flat on the same runs: an A/A baseline-vs-baseline control measured +0.06% median (rejected), a module-independent
control_spreadmeasured −3.1% raw / +0.7% median, and untouched ops (spread10,merge_refsunder the second change) all paired to ≈0% median — so the wins are the changes, not machine noise. Every measured pair also produced identical semantic checksums (applied values, cleanup call order, thrown-error propagation).Scope and limitations
apply_ref_value's single-ref path keeps its lone-closure shape, which is already optimal there. Two other candidates in the same hunt were measured and rejected:propertyIsEnumerablein place ofget_descriptorregressedspread10by ~8%, and eliding the second copy innormalize_spread_props_for_ref_attrproduced no win. Both were restored.mergeRefs/merge_ref_propscharacterization covering cleanup order, thrown callbacks, thrown cleanups,current/value/branded refs, array refs, and array/DOM-like exclusions), and the full test suite except 8 files that fail identically on the unmodified baseline (unbuilteslint-parser, fixturetscsubprocesses — environmental).