Skip to content

perf(runtime): speed up iterable_array_from for arrays - #59

Merged
trueadm merged 2 commits into
mainfrom
cursor/iterable-array-from-fast-path-a2d4
Sep 4, 2026
Merged

trueadm merged 2 commits into
mainfrom
cursor/iterable-array-from-fast-path-a2d4

Conversation

@jonkwheeler

@jonkwheeler jonkwheeler commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

iterable_array_from accepted arrays but always walked Symbol.iterator, allocating an iterator and a { value, done } result per element. Arrays now use iterable.slice(index), which keeps holes in holey arrays.

Sets, raw iterators, and array-likes are unchanged.

Audit notes

@tsrx/runtime is compiler helpers (refs, spreads, @for mapping), not a signals/effects runtime. Other hot paths were measured before landing this:

  • map_iterable / map_array — already specialized for arrays. Preallocation, native map, and flatten variants were mixed or regressing across list sizes (10 / 100 / 1000) and vnode vs text vs fragment workloads.
  • normalize_spread_props — rest-arg removal and indexed ownKeys were inside noise (~1–4%). This path was just tuned in perf(runtime): speed up ordinary spread normalization #42.
  • normalize_spread_props_for_ref_attr in-place defineProperty — ~0–3%, overlapping quartiles.
  • exclude_prop_from_object defineProperties batch — −20%.

Only the array fast path in iterable_array_from was a clear, reproducible win.

Benchmarks

Node v22.14.0, linux x64, isolated perf_hooks microbenchmarks (warmup 200ms, 400ms × 13 runs, median).

Array.prototype.slice vs the previous iterator walk (same-process bake-off):

Workload Before (iterator) slice Delta
array 100, index 0 2,232,508 ops/s 14,768,076 ops/s +561%
array 100, index 10 2,266,330 ops/s 15,465,162 ops/s +582%
array 1000, index 0 233,020 ops/s 3,150,961 ops/s +1252%

Set / iterator workloads stay on the existing path.

Test plan

  • Runtime coverage for dense slice, index edge cases, holey-array holes, Set, iterator, and array-like
  • pnpm exec vitest run on language-helpers runtime and type tests (2 files, 15 tests) after the review follow-up
Open in Web Open in Cursor 

Copy array elements by index instead of allocating an iterator and a
{ value, done } result per item. Skip comparison and sparse-hole
materialization stay aligned with the iterator path.

Co-authored-by: Jon Wheeler <[email protected]>
@vercel

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

Request Review

Comment on lines +94 to +96
if (is_array(iterable)) {
return array_from_index(iterable, index);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need an extra function, this should just be:

Suggested change
if (is_array(iterable)) {
return array_from_index(iterable, index);
}
if (is_array(iterable)) {
return array.slice(index);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reason is if it's even a holey array, we still want holes to be present, we're not changing that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped the helper and switched the array path to iterable.slice(index), so holey arrays keep their holes. Tests now assert slice hole semantics.

@cursor

cursor Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

READY FOR REVIEW

Use Array.prototype.slice for the array fast path and keep holes in
holey arrays, as requested in review.

Co-authored-by: Jon Wheeler <[email protected]>
@trueadm
trueadm merged commit e3eaa41 into main Sep 4, 2026
11 checks passed
@trueadm
trueadm deleted the cursor/iterable-array-from-fast-path-a2d4 branch September 4, 2026 20:00
@github-actions github-actions Bot mentioned this pull request Sep 4, 2026
cursor Bot pushed a commit that referenced this pull request Sep 4, 2026
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]>
cursor Bot pushed a commit that referenced this pull request Sep 4, 2026
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]>
cursor Bot pushed a commit that referenced this pull request Sep 4, 2026
…#66)

* perf(runtime): speed up iterable_array_from for length-bearing values

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]>

* fix(runtime): keep string iterable_array_from on the iterator path

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]>

* fix(runtime): satisfy typecheck after the #59 merge

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]>

---------

Co-authored-by: Cursor Agent <[email protected]>
Co-authored-by: Jon Wheeler <[email protected]>

This branch was successfully deployed

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

4 participants