This repository was archived by the owner on Aug 21, 2026. It is now read-only.
perf: drop per-element wrapper indirection on offset=0 iterator path - #34
Open
Farenheith wants to merge 1 commit into
Open
perf: drop per-element wrapper indirection on offset=0 iterator path#34Farenheith wants to merge 1 commit into
Farenheith wants to merge 1 commit into
Conversation
augmentativeIterateIterable previously wrapped every next() call in a '() => current()' closure even when no skip offset was set. For the common offset=0 case, return finalNext directly as next(), removing one call frame per element for non-array iterables. The skip (offset>0) path keeps its original stable-wrapper semantics: consumers may cache the function reference, so reassigning iterator.next after first use is unsafe — only an internal closure variable is swapped. Measured (interleaved A/B, 100k elements): gen->array addMap -10.8%, filter+map chain -3.8%. Array path and async path are untouched.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
What
augmentativeIterateIterablepreviously wrapped everynext()call in a() => current()closure even when no skip offset was set. For the common offset=0 case, returnfinalNextdirectly asnext(), removing one call frame per element for non-array iterables.Why it's safe
offset > 0) is byte-identical in semantics to before: stable outer wrapper + internal closure-variable swap. (Reassigningiterator.nextafter first use would be unsafe — consumers like V8'sfor...ofcan cache the function reference, so only an internal variable may change.)augmentativeIteratedispatches arrays to a separate function; async already has minimal indirection by design).Verification
Notes
This is the one remaining safe micro-opt from the Aug 2026 perf analysis pass (destructuring, bind-caching and toArray pre-allocation were measured as noise/harmful and ruled out).