Skip to content

perf(runtime): speed up merging three or more refs - #69

Merged
leonidaz merged 2 commits into
mainfrom
perf/runtime-hot-path-20260905
Sep 5, 2026
Merged

leonidaz merged 2 commits into
mainfrom
perf/runtime-hot-path-20260905

Conversation

@jonkwheeler

@jonkwheeler jonkwheeler commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Merging three refs takes 43–46% less time in repeated Node 22 and 24 measurements. The runtime reuses its private argument array, avoiding a second allocation while preserving ref identity, order, attachment, and cleanup behavior.

Measurements

Baseline: de31ea41 on main; candidate: e4649e57. Values are raw median nanoseconds per operation. Reduction is the median of 12 paired raw-time reductions, so it can differ slightly from the ratio of the two medians.

Engine / fresh process Three-ref merge before After Paired reduction Merge + attach + cleanup reduction
Node 22.22.2 / 1 46.79 26.87 43.44% 15.71%
Node 22.22.2 / 2 47.82 26.39 45.65% 14.81%
Node 24.19.0 / 1 48.42 26.60 46.02% 17.00%
Node 24.19.0 / 2 49.02 27.04 44.07% 17.51%

CPU profiling attributed 42.1% of merge_ref_props source-position samples to the original filter line. Instrumented timings were excluded from the comparison.

The primary workload was fixed before editing: one callback ref, one { current } ref, and one { value } ref, with 400,000 merges per batch. Each process imported the actual baseline and candidate modules, warmed each with half a batch then a full batch, and ran 12 pairs in alternating order. Returned values escaped into a 256-entry ring and contributed to consumed checksums; lifecycle runs also checked final ref/callback state. Benchmarks ran separately from tests and builds.

Two independent baseline/baseline runs per engine established primary noise floors of 2.99% and 5.86%. The largest individual primary A/A changes were 39.41% and 32.23%; all outliers remained in the raw data, and acceptance used the preregistered median statistic. Every candidate run exceeded the 5% target and its noise floor with improving raw medians. Unchanged 0/1/2-ref paths, native slice, and ref branding stayed within the registered control limits. All-live and interleaved-nullish workloads at 3/8/32 refs showed no material regressions.

These are isolated helper measurements; browser-engine and whole-application rendering gains were not measured. The one-off harness and raw measurements are retained as local working evidence rather than added as a new benchmark subsystem.

Validation

  • pnpm test: 3,329 passed, 33 skipped across 79 files.
  • Shared utility and all four target-runtime projects: 743 passed.
  • New focused ref characterization passed 35/35 on the baseline before the production edit, then on the changed implementation.
  • pnpm typecheck, pnpm format:check, and pnpm changeset:check: passed.
  • Patch changeset for @tsrx/runtime.

The full local run required building the ESLint parser and TypeScript CLI and allowing the tests' loopback HTTP server. No browser routes changed.

Review found no actionable defects. One optional coverage suggestion remains: add a dedicated durable lifecycle assertion for three all-non-null refs; the benchmark exercises that input, while committed tests emphasize nullish compaction and identity/order/cleanup cases.


Compound Engineering


Note

Low Risk
Localized performance refactor in ref merging with broad characterization tests; 0–2 ref paths unchanged and semantics are explicitly preserved.

Overview
merge_ref_props in @tsrx/runtime no longer calls Array.filter when there are three or more inputs. It compacts nullish entries in place on the rest-args array (copy survivors forward, then shorten length when needed), which removes a second array allocation while keeping the same early returns for 0/1/2 refs.

Behavior is locked down with new Vitest coverage: surviving ref identity when only one ref remains, the caller’s refs array is not mutated on the identity fast paths, attach/cleanup order for mixed callback and object refs, and error propagation when a ref throws during attach or cleanup.

A patch changeset documents the runtime tweak.

Reviewed by Cursor Bugbot for commit 9d0e009. Bugbot is set up for automated code reviews on this repo. Configure here.

@vercel

vercel Bot commented Sep 5, 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 5, 2026 9:52pm UTC
tsrx-website-mcp Ready Ready Preview Sep 5, 2026 9:52pm UTC

Request Review

@leonidaz
leonidaz merged commit ebab7e0 into main Sep 5, 2026
11 checks passed
@leonidaz
leonidaz deleted the perf/runtime-hot-path-20260905 branch September 5, 2026 22:09
@github-actions github-actions Bot mentioned this pull request Sep 5, 2026

This branch was successfully deployed

2 active deployments
Preview – tsrx-website — 9d0e0098 Deployed Sep 5, 2026 by vercel[bot]
Preview – tsrx-website-mcp — 9d0e0098 Deployed Sep 5, 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