Repository navigation
perf(runtime): speed up iterable_array_from for length-bearing values - #66
Conversation
Copy indexed elements for non-array array-likes, arguments, strings, and typed arrays instead of walking Symbol.iterator or allocating through Array.from().slice(). Arrays stay on the iterator path. Co-authored-by: Jon Wheeler <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
READY FOR REVIEW |
|
Address the PR feedback from cursor please |
String.prototype[Symbol.iterator] yields Unicode code points, so the indexed copy split non-BMP surrogate pairs and changed skip offsets. Co-authored-by: Jon Wheeler <[email protected]>
|
Addressed the Bugbot string surrogate-pair feedback: |
Keep #59 array slice path and this branch's non-array indexed copy. Strings stay on the iterator path. Co-authored-by: Jon Wheeler <[email protected]>
Declare arguments-IIFE parameters so checkJs accepts the call, and narrow length access on the iterable union without changing runtime behavior. Co-authored-by: Jon Wheeler <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 0f53225. Configure here.
| start += 1; | ||
| } | ||
| return copy_from_offset(array_like, start, length); | ||
| } |
There was a problem hiding this comment.
Indexed copy throws on invalid length
Medium Severity
array_from_index passes the raw length into copy_from_offset, which then does new Array(count). Any value whose iterator is Array.prototype[Symbol.iterator] with a non-integer, negative, NaN, or infinite length now throws RangeError. The previous iterator walk applied ToLength and returned a normal array.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 0f53225. Configure here.
| if (!Number.isFinite(start)) { | ||
| start = 0; | ||
| } | ||
| start = Math.trunc(start); |
There was a problem hiding this comment.
Infinity index copies entire array-like
Low Severity
array_like_from_index maps every non-finite index to 0, including Infinity. Array.from(x).slice(Infinity) returns an empty array, so a non-iterable array-like now returns every element instead of none.
Reviewed by Cursor Bugbot for commit 0f53225. Configure here.


Summary
Second-pass runtime audit after #59. That PR owns the array fast path in
iterable_array_from; this change does not touch arrays.Non-array length-bearing values were still paying the slow path:
{ length, 0, 1, … }with no iterator) usedArray.from(x).slice(index)— two allocations plus a slice.arguments, strings, and typed arrays have a numericlengthwhose default iterator just walks indexes, but we still allocated an iterator and a{ value, done }result per element.Those now take an indexed copy. Custom iterators that also happen to have
lengthstill win (so{ length: 2, [Symbol.iterator]: … }is unchanged). Sets, Maps, generators, and arrays stay on the iterator walk.Skip semantics match the previous path:
arguments/ strings / typed arrays keep iterator skip (start < index), so negative, fractional, andNaNindexes match.Array.from(x).slice(index)start rules. Sparse holes still become ownundefinedentries.Audit notes
Measured on Node
v22.14.0, linux x64, isolatedperf_hooksprocesses (warmup 200ms, 400ms × 13 runs, median). Candidates that did not ship:map_iterableprealloc / index-assign — mixed (text +25%, fragment −3.5%), same as the last auditArray.frominiterable_array_from— −59% to −63% when isolated (the in-process +191% was noise)Iterator.fromfor raw iterators — +4.7% isolated (inside noise)array_slicerest-arg removal — 0–3%exclude_prop_from_objectviaObject.keys— ~11%, plus a closure-correctness riskescapeindexOffast path — +28% clean / −21% dirtycreate_ref_propsymbol assign — +330% but not compiler-emitted and would make the brand enumerablenormalize_spread_props— observation tests lockownKeys+ per-key descriptors; last pass already tuned this in perf(runtime): speed up ordinary spread normalization #42Target runtimes (React/Preact/Solid/Vue) are re-exports plus error-boundary wrappers. No additional client/JSX/hydration helpers to tune.
Benchmarks
Node
v22.14.0, linux x64. Isolated processes. After column is the real@tsrx/runtimeexport.Arrays and Sets are intentionally unchanged (iterator path). #59 covers arrays.
Test plan
pnpm test --project tsrx-utils(20 files, 506 tests)prettier --checkon touched files;pnpm changeset:check