Repository navigation
perf: single-pass ref classification and flat array-ref cleanups - #116
Merged
Merged
Conversation
is_ref_object ran is_dom_node plus its own-property and prototype-accessor
probes once per key ('current', then 'value'). Replace the two calls with a
single ref_object_prop classification that preserves probe order, and make
apply_ref_value collect array refs as flat [kind, payload] cleanup pairs
instead of allocating a closure per item.
Measured -10% to -31% on object-ref and mixed-array attach paths; callback
and normalize controls within noise.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Merged
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
Object-ref classification and array-ref attach are now ~10-31% faster on the hot paths. Each call to
is_ref_objectranis_dom_nodeplus its own-property and prototype-accessor probes, andapply_ref_value,mergeRefs, andcollect_ref_cleanupscalled it twice per ref (once forcurrent, once forvalue). A newref_object_prophelper runs the DOM-node check and all key probes once, preserving the original classification order (currentprecedence,__v_isRefbefore own/prototypevalue). Array-valued refs previously allocated a closure per item; they now collect flat[kind, payload]cleanup pairs and return a single replay closure.Measurements
Same-process interleaved A/B against a baseline module copy, median ns/call:
apply_ref_valueplain non-ref objectapply_ref_value{ value }refapply_ref_valuemergeRefswith 3 value refsControls (callback refs,
mergeRefsfunction refs,normalize_spread_props*paths) measured within the demonstrated noise band on the same runs. The cleanup replay loop stays inline at all three call sites deliberately: extracting a sharedreplay_ref_cleanupshelper was benchmarked and regressed callback-ref paths ~12-19%, so each site carries a comment pinning the duplication.Residual risk
ref_object_proptakes a single snapshot:is_dom_noderuns once per classification where baseline ran it once per probed key. An object whosenodeType/nodeNamegetters or Proxy traps mutate its own shape mid-classification can therefore observe one fewer trap sequence, and a pathological accessor can flip the verdict entirely (both directions verified by PoC). No in-repo emitter or real ref object produces such shapes, no test pins the behavior, and re-probing would defeat the optimization — noted here so the delta is explicit rather than silent.Test plan
packages/tsrx/tests/utils/ref-runtime.test.js— 56 tests, including new pins forcurrent-over-valueprecedence, primitive-ref TypeError, array cleanup replay order, and the empty-arrayundefinedsentineltsrx-utilsproject — 627 testspnpm typecheck,pnpm format:check, changeset check — all cleanNote
Medium Risk
Hot-path ref semantics changed for edge cases (objects with both
currentandvalue, pathological getters/Proxies during classification); well-tested for normal ref shapes but classification is now a single snapshot vs double-probe.Overview
Speeds up ref attach/teardown in
@tsrx/runtimeby classifying object refs once per value instead of probingcurrentandvalueseparately (which duplicated the DOM-node check).Replaces
is_ref_objectwithref_object_prop, used frommergeRefs,apply_ref_value, andcollect_ref_cleanups, keeping the same resolution order (currentovervalue, Vue__v_isRef, inheritedvalueaccessors). Array-valued refs inapply_ref_valuenow go throughapply_ref_array, building flat[kind, payload]cleanup pairs like the merge path instead of one nested closure per item. The cleanup replay loop stays duplicated inline at three call sites on purpose (a shared helper regressed benchmarks).Types and tests are updated:
ref.d.tspoints atref_object_prop, andref-runtime.test.jspinscurrent-over-value, primitive ref TypeError, array cleanup order, and empty-arrayundefinedbehavior, plus extranormalize_spread_props_for_ref_attrcoverage.Reviewed by Cursor Bugbot for commit db860dc. Bugbot is set up for automated code reviews on this repo. Configure here.