Repository navigation
[VM] Speed up TypedArray creation from arrays - #2219
Open
goutamadwant wants to merge 2 commits into
Open
goutamadwant wants to merge 2 commits into
goutamadwant wants to merge 2 commits into
Conversation
Avoid iterator and iterator-result allocations when a JSArray uses the built-in array iterator methods. Preserve dynamic length, indexed access, and snapshot semantics while falling back for customized iterators. Add regression coverage for array growth and shrinkage, conversion and mapping side effects, and customized iterator methods. Fixes facebook#2215
1 of 2 tasks
lavenzg
requested changes
Oct 7, 2026
| // Avoid allocating iterator and iterator-result objects for ordinary arrays. | ||
| // Both methods must be unmodified because the generic iterator protocol | ||
| // observes each of them. | ||
| auto sourceArray = Handle<JSArray>::dyn_vmcast(items); |
Contributor
There was a problem hiding this comment.
Can you put this in a new method, iterableToArrayLikeFastPath?
| while (k < JSArray::getLength(*lv.sourceArray, runtime)) { | ||
| GCScopeMarkerRAII marker{gcScope}; | ||
|
|
||
| lv.nextValue = lv.sourceArray->at(runtime, k).unboxToHV(runtime); |
Contributor
There was a problem hiding this comment.
I think ideally we want to to have another fast path for arrays that has no accessors and indexed properties in bound (see arrayFastPathCheck()).
This branch has not been 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
Add a guarded fast path for creating typed arrays from plain
JSArrayvalues when both the array iterator and itsnextmethod are unchanged.The fast path avoids allocating iterator and iterator-result objects while preserving dynamic array length, indexed getters, value snapshot semantics, and customized iterator behavior. Inputs that do not meet the guards continue through the generic iterable path.
Add regression coverage for array growth and shrinkage, conversion and mapping side effects, and customized iterator methods.
Fixes #2215
Test Plan
./utils/format.shLIT_OPTS=-j1 cmake --build cmake-build-release --target check-hermes -j 8Float64Array.from(array): 99 msnew Float64Array(array): 92 msUint8Array.from(array): 94 ms