Skip to content

perf(runtime): make merged refs ~24-34% faster to mount and unmount - #104

Merged
trueadm merged 2 commits into
mainfrom
jon/perf-runtime-hot-path-20260913
Sep 13, 2026
Merged

trueadm merged 2 commits into
mainfrom
jon/perf-runtime-hot-path-20260913

Conversation

@jonkwheeler

@jonkwheeler jonkwheeler commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The two helpers the compilers emit when an element's refs need merging — mergeRefs (explicit ref plus a spread that may carry one) and merge_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.

Op Raw Δ Median paired Δ MAD Pairs Accepted
merge_refs (4 refs + spread-carried) +23.9% / +24.7% +24.8% / +24.0% 1.2% / 1.4% 2×11 yes, two independent runs
merge_refs2 (2 refs, common shape) +26.2% +24.8% 3.3% 11 yes
merge_props2 (2 refs via merge_ref_props) +28.0% / +30.9% +31.3% / +30.6% 8.8% / 3.3% 2×11 yes, two independent runs
merge_props4 (4 mixed refs via merge_ref_props) +39.9% / +32.7% +36.2% / +34.2% 3.7% / 3.1% 2×11 yes, two independent runs

Controls stayed flat on the same runs: an A/A baseline-vs-baseline control measured +0.06% median (rejected), a module-independent control_spread measured −3.1% raw / +0.7% median, and untouched ops (spread10, merge_refs under 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

  • These are helper-call times, not an end-to-end app metric; real-world gain scales with how often merged refs mount/unmount.
  • Only the two merge helpers changed; 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: propertyIsEnumerable in place of get_descriptor regressed spread10 by ~8%, and eliding the second copy in normalize_spread_props_for_ref_attr produced no win. Both were restored.
  • Pre-push suites passed: typecheck across all runtime packages, the ref-runtime test file (42 tests, including mergeRefs/merge_ref_props characterization 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 (unbuilt eslint-parser, fixture tsc subprocesses — environmental).

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.
@vercel

vercel Bot commented Sep 13, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
tsrx-website Ready Ready Preview Sep 13, 2026 4:19pm UTC
tsrx-website-mcp Ready Ready Preview Sep 13, 2026 4:19pm UTC

Request Review

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.
@jonkwheeler jonkwheeler changed the title perf(runtime): make merged refs ~24% faster to mount and unmount perf(runtime): make merged refs ~24-34% faster to mount and unmount Sep 13, 2026

This branch was successfully deployed

2 active deployments
Preview – tsrx-website — 3c57e7d9 Deployed Sep 13, 2026 by vercel[bot]
Preview – tsrx-website-mcp — 3c57e7d9 Deployed Sep 13, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants