perf(array): add dense fast path to Array.prototype.push#5300
Open
tkshsbcue wants to merge 1 commit intoboa-dev:mainfrom
Open
perf(array): add dense fast path to Array.prototype.push#5300tkshsbcue wants to merge 1 commit intoboa-dev:mainfrom
tkshsbcue wants to merge 1 commit intoboa-dev:mainfrom
Conversation
Test262 conformance changes
Broken tests (3):Tested main commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5300 +/- ##
===========================================
+ Coverage 47.24% 59.64% +12.40%
===========================================
Files 476 589 +113
Lines 46892 63588 +16696
===========================================
+ Hits 22154 37930 +15776
- Misses 24738 25658 +920 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
447ebbe to
39e6041
Compare
Array.prototype.push was going through the generic [[Set]] machinery for every element, which involves property descriptor validation and prototype chain walks. This is unnecessary for dense arrays where we can append directly to the indexed storage. Add a fast path that mirrors the PushValueToArray opcode: verify the array is extensible and its shape matches the default array template (guaranteeing length is writable), then push directly via push_dense() and update the length in-place. Falls through to the existing slow path for sparse arrays, non-extensible arrays, arrays with modified property descriptors, and array-like objects. ~49% improvement on a push-dominated microbenchmark, ~20% on a realistic mixed workload (push objects + filter).
39e6041 to
372c580
Compare
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.
perf(array): add dense fast path to Array.prototype.push
Description
Array.prototype.pushgoes through the generic[[Set]]path for every element — converting the index to aPropertyKey, cloning the receiver, calling__get_own_property__, then__define_own_property__with full descriptor validation. For dense arrays, none of this is necessary.The
PushValueToArrayopcode (used for array literals like[1, 2, 3]) already has a fast path that appends directly to dense indexed storage viapush_dense(). This PR applies the same pattern to theArray.prototype.pushbuiltin.How it works
Before entering the generic
[[Set]]loop, check if the object is an extensible array with dense storage. If so, push each element directly viapush_dense()and update the length in-place.push_dense()handles type transitions (DenseI32 → DenseF64 → DenseElement) internally and only returnsfalsefor already-sparse storage, so the first push serves as a probe — if it succeeds, all subsequent pushes are guaranteed to succeed.The fast path is skipped for:
Object.preventExtensions,Object.freeze,Object.seal)The slow path is completely untouched.
Benchmark results
Criterion microbenchmark (200 iterations × 5000 integer pushes):
This is a push-dominated benchmark. On a more realistic workload (pushing objects + filtering), the improvement is smaller since push is no longer the bottleneck:
Improvement ranges from ~20% (mixed workloads) to ~49% (push-dominated) depending on how much time is spent in push.