Skip to content

perf(array): add dense fast path for Array.prototype.splice#5328

Open
tkshsbcue wants to merge 1 commit intoboa-dev:mainfrom
tkshsbcue:perf/array-splice-dense-fast-path
Open

perf(array): add dense fast path for Array.prototype.splice#5328
tkshsbcue wants to merge 1 commit intoboa-dev:mainfrom
tkshsbcue:perf/array-splice-dense-fast-path

Conversation

@tkshsbcue
Copy link
Copy Markdown
Contributor

Related to #3407.

Right now splice on a dense array still goes through the full generic path — individual Get/Set/DeletePropertyOrThrow per element. Same approach as the existing shift fast path, this skips all of that and operates on the ThinVec directly via ThinVec::splice.

Handles DenseI32, DenseF64, and DenseElement. If replacement items don't match the storage type (e.g. string into an i32 array), converts to DenseElement first.

The fast path only kicks in when:

  • It's a real array with the default shape (no subclass / custom @@species)
  • itemCount <= actualDeleteCount so no new indices are created beyond len - 1, avoiding the prototype-chain-setter issue from Optimize array unshift #5076
  • len <= vec.len() (storage matches length)

Falls through to the generic path otherwise.

~25% faster on a benchmark doing repeated splices on 500-element dense arrays.

Partially addresses boa-dev#3407.

Operate directly on the underlying ThinVec storage when the array
is dense, using ThinVec::splice for removal and replacement in a
single pass instead of per-element Get/Set/DeletePropertyOrThrow.

Guarded by itemCount <= actualDeleteCount to avoid creating new
indices where prototype chain setters could fire, and by a shape
check to ensure ArraySpeciesCreate would return a plain Array.
@tkshsbcue tkshsbcue requested a review from a team as a code owner April 13, 2026 14:55
@github-actions github-actions bot added C-Builtins PRs and Issues related to builtins/intrinsics Waiting On Review Waiting on reviews from the maintainers labels Apr 13, 2026
@github-actions github-actions bot added this to the v1.0.0 milestone Apr 13, 2026
@github-actions
Copy link
Copy Markdown

Test262 conformance changes

Test result main count PR count difference
Total 53,125 53,125 0
Passed 51,049 51,049 0
Ignored 1,482 1,482 0
Failed 594 594 0
Panics 0 0 0
Conformance 96.09% 96.09% 0.00%

Tested main commit: 3cec5e6bc4454077cb8d65b537d368d633137e0e
Tested PR commit: 1536cdec1b4630e616af61c0d928e31970fec8c1
Compare commits: 3cec5e6...1536cde

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 13, 2026

Codecov Report

❌ Patch coverage is 56.41026% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.79%. Comparing base (6ddc2b4) to head (1536cde).
⚠️ Report is 951 commits behind head on main.

Files with missing lines Patch % Lines
core/engine/src/builtins/array/mod.rs 56.41% 17 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #5328       +/-   ##
===========================================
+ Coverage   47.24%   59.79%   +12.55%     
===========================================
  Files         476      590      +114     
  Lines       46892    63734    +16842     
===========================================
+ Hits        22154    38111    +15957     
- Misses      24738    25623      +885     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-Builtins PRs and Issues related to builtins/intrinsics Waiting On Review Waiting on reviews from the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant