Skip to content

Perf/array push pop dense fast path#5283

Closed
MayankRaj435 wants to merge 3 commits intoboa-dev:mainfrom
MayankRaj435:perf/array-push-pop-dense-fast-path
Closed

Perf/array push pop dense fast path#5283
MayankRaj435 wants to merge 3 commits intoboa-dev:mainfrom
MayankRaj435:perf/array-push-pop-dense-fast-path

Conversation

@MayankRaj435
Copy link
Copy Markdown

Summary

This PR implements fast-path optimizations for Array.prototype.push and Array.prototype.pop when dealing with arrays that have contiguous, "dense" index storage. By bypassing the generic property map lookups and standard [[Get]]/[[Set]] internal methods, we significantly reduce the overhead for these fundamental operations.

Related Issue

Fixes #5281

Key Changes

  • IndexedProperties (property_map.rs):
    • Added pop_dense() method to natively remove elements from dense vectors (DenseI32, DenseF64, and DenseElement).
    • Added len() and is_sparse() helper methods to facilitate fast check logic.
  • Array.prototype.pop (array/mod.rs):
    • Introduced a fast path that checks if the object is a standard array with dense storage.
    • Directly removals the last element and updates the length property, avoiding string conversion and map lookups.
  • Array.prototype.push (array/mod.rs):
    • Introduced a fast path that iterates over arguments and used push_dense.
    • Added an extensible check to ensure strict compliance when adding new properties to non-extensible arrays.
    • Updates the length property once at the end of the operation.

Verification

  • Unit Tests: Passed cargo test array in core/engine (123 tests).
  • CI: local cargo clippy and cargo fmt passed (as seen in the command logs).

Performance Impact

Initial microbenchmarks suggest a significant reduction in cycles for push and pop on dense arrays, as we now avoid:

  1. Numeric index stringification.
  2. Property descriptor map lookups.
  3. Multiple internal method calls per argument.

MayankRaj435 added 3 commits March 28, 2026 23:00
Introduce a dedicated ArrowFunction struct that implements a specialized
__call__ handler, bypassing the constructor check and this-binding
resolution that are unnecessary for arrow functions.

Arrow functions:
- Are never constructors (skip is_class_constructor check)
- Always have lexical this (skip this-binding resolution)
- Don't need [[Fields]] or [[PrivateMethods]] slots

This reduces the per-call overhead for arrow functions by ~26% in
microbenchmarks (100M calls: 21.0s -> 15.6s in release mode).

The approach follows the maintainer-recommended strategy of specializing
at the function object layer rather than adding new VM opcodes, keeping
the Instruction enum lean (24 bytes) and avoiding dispatch sensitivity.
- Implement ScriptFunction trait for polymorphic ArrowFunction/OrdinaryFunction access
- Refactor all downcast_ref sites (toString, function_call, get_function_realm, etc.)
- Update GetHomeObject/SetHomeObject opcodes for ArrowFunction support
- Fix perform_eval and has_super_binding for ArrowFunction
- Apply cargo fmt formatting
@github-actions github-actions bot added Waiting On Review Waiting on reviews from the maintainers C-Builtins PRs and Issues related to builtins/intrinsics C-VM Issues and PRs related to the Boa Virtual Machine. and removed Waiting On Review Waiting on reviews from the maintainers labels Mar 29, 2026
@github-actions github-actions bot added this to the v1.0.0 milestone Mar 29, 2026
@github-actions
Copy link
Copy Markdown

Test262 conformance changes

Test result main count PR count difference
Total 52,963 52,963 0
Passed 50,732 50,728 -4
Ignored 1,426 1,426 0
Failed 805 809 +4
Panics 0 0 0
Conformance 95.79% 95.78% -0.01%
Broken tests (4):
test/staging/sm/Array/set-with-indexed-property-on-prototype-chain.js (previously Passed)
test/built-ins/Array/prototype/push/set-length-array-length-is-non-writable.js (previously Passed)
test/built-ins/Array/prototype/push/set-length-array-is-frozen.js (previously Passed)
test/built-ins/Array/prototype/pop/S15.4.4.6_A4_T1.js (previously Passed)

Tested main commit: f075094f9674f9919b4d2e85ca1bcba410bf34b0
Tested PR commit: 1640f1cb862533bfdd4d377780be7a7da20d2173
Compare commits: f075094...1640f1c

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 29, 2026

Codecov Report

❌ Patch coverage is 72.81553% with 56 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.68%. Comparing base (6ddc2b4) to head (1640f1c).
⚠️ Report is 921 commits behind head on main.

Files with missing lines Patch % Lines
core/engine/src/builtins/function/mod.rs 67.67% 32 Missing ⚠️
core/engine/src/object/property_map.rs 64.70% 6 Missing ⚠️
core/engine/src/vm/code_block.rs 84.61% 6 Missing ⚠️
core/engine/src/vm/opcode/function.rs 64.28% 5 Missing ⚠️
core/engine/src/builtins/eval/mod.rs 66.66% 3 Missing ⚠️
...e/src/environments/runtime/declarative/function.rs 50.00% 3 Missing ⚠️
core/engine/src/builtins/array/mod.rs 95.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #5283       +/-   ##
===========================================
+ Coverage   47.24%   59.68%   +12.44%     
===========================================
  Files         476      589      +113     
  Lines       46892    63632    +16740     
===========================================
+ Hits        22154    37981    +15827     
- Misses      24738    25651      +913     

☔ 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.

@MayankRaj435
Copy link
Copy Markdown
Author

Hey maintainers ,please review it and let me know if any changes required

@jedel1043 jedel1043 closed this Mar 29, 2026
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 C-VM Issues and PRs related to the Boa Virtual Machine.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Array.prototype Operations Fast-Path Optimization

2 participants