Repository navigation
perf(runtime): speed up merging three or more refs - #69
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
leonidaz
approved these changes
Sep 5, 2026
Merged
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
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:
de31ea41onmain; 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.CPU profiling attributed 42.1% of
merge_ref_propssource-position samples to the originalfilterline. 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.pnpm typecheck,pnpm format:check, andpnpm changeset:check: passed.@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.
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_propsin@tsrx/runtimeno longer callsArray.filterwhen there are three or more inputs. It compacts nullish entries in place on the rest-args array (copy survivors forward, then shortenlengthwhen 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.