Repository navigation
perf(runtime): speed up map_iterable for arrays and sized collections - #67
Merged
Merged
Conversation
jonkwheeler
marked this pull request as ready for review
September 4, 2026 18:14
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
READY FOR REVIEW |
Contributor
|
typechecks are not passing. |
Contributor
|
@leonidaz typecheck is fixed on this branch. The TS7006 errors were the untyped
|
Preallocate the result after the first mapped value so the common single-node @for body avoids repeated push, and use Set/Map size for is_last instead of peeking the next iterator result. Fragment bodies and custom iterators keep the previous push / peek-ahead paths. Co-authored-by: Jon Wheeler <[email protected]>
Add JSDoc types so checkJs no longer reports implicit any on the iterable runtime test helper and the empty result accumulators. Co-authored-by: Jon Wheeler <[email protected]>
cursor
Bot
force-pushed
the
cursor/map-iterable-dispatch-sized-ca6d
branch
from
September 4, 2026 22:46
3f96e3f to
cdf20d3
Compare
leonidaz
approved these changes
Sep 5, 2026
Merged
leonidaz
added a commit
that referenced
this pull request
Sep 7, 2026
…erable (#86) The sized fast path added in #67 cached `size` and read `iterator.next().value` without checking `done`, so a callback that cleared, deleted from, or added to the Set or Map being iterated received `undefined` items, missed added entries, and saw `is_last` on the wrong item. Route Set and Map back through the peek-ahead iterator path and keep the array preallocation. Reported downstream as octanejs/octane#977. Co-authored-by: Claude Fable 5.1 <[email protected]>
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
Third-pass runtime audit after #59 and #66. Those PRs own
iterable_array_from; this change does not touch it.map_iterableis the compiler-emitted@forhelper on React/Preact. Two costs showed up in measurement:push.Set/Mappaid twoiterator.next()calls per item just to computeis_last.The first mapped value now chooses the path: a single node preallocates; an array-valued (fragment) result keeps the previous push-flatten loop.
SetandMapusesizeforis_lastthe same way arrays already uselength. Custom iterators that happen to havesizestill peek ahead.Audit notes
Measured on Node
v22.14.0, linux x64, isolatedperf_hooksprocesses (warmup 200ms, 400ms × 13 runs, median). Candidates that did not ship:map_iterablealways-prealloc / mid-loop hybrid — fragment lists still regress (same mixed result as prior audits)escapereplace— slower on clean and dirty short stringsescapecharCodeAt— +24% to +85% dirty, −73% on clean medium textarray_sliceexplicitstart/endvs rest/spread — 0% once compared to the real implementationexclude_prop_from_objectviaObject.keys+ symbols — +10% to +16%, same band previously discarded, and not compiler-emitted#59/#66
iterable_array_frompaths were not revisited.Benchmarks
Node
v22.14.0, linux x64. Isolated processes. After column is the real@tsrx/runtimemap_iterableexport.@for)Generators stay on the peek-ahead path (control). Fragment bodies stay on push-flatten.
Test plan
is_last, fragment flatten, mixed later-array flatten, Set/Map sizeis_last, custom iterator+size, generators/raw iterators, empty/tail, non-iterable rejectpnpm exec vitest run --project tsrx-utils(21 files, 509 tests)prettier --checkon touched files;pnpm changeset:check