Skip to content

perf(allocator): per-platform Arena::new_fixed_size implementations#22088

Merged
graphite-app[bot] merged 1 commit intomainfrom
om/05-02-refactor_allocator_per-platform_arena_new_fixed_size_implementations
May 2, 2026
Merged

perf(allocator): per-platform Arena::new_fixed_size implementations#22088
graphite-app[bot] merged 1 commit intomainfrom
om/05-02-refactor_allocator_per-platform_arena_new_fixed_size_implementations

Conversation

@overlookmotel
Copy link
Copy Markdown
Member

@overlookmotel overlookmotel commented May 2, 2026

Introduce separate Arena::new_fixed_size implementations for different platforms.

Different platforms have differing abilities to service allocation requests with high alignment, so a different allocation strategy is appropriate for each:

  • Mac OS: System allocator refuses 4 GiB-aligned allocation requests. Allocate ~4 GiB with 2 GiB alignment, then use either the top or bottom half for the arena chunk.
  • Windows: System allocator cannot service allocations with any alignment over 16. Allocate ~6 GiB with 16 alignment, and then find a ~2 GiB block within that allocation which is aligned on 4 GiB. This is what std was doing already, but implementing it ourself sidesteps an annoyance with std's implementation.
  • Linux: System allocator can service high-alignment requests, so just ask for exactly what we want (~2 GiB with 4 GiB alignment).

This reduces virtual memory usage on Linux, side-steps std's workaround on Windows, and is unchanged for Mac OS.

This also prepares the way for using VirtualAlloc-based allocation on Windows, to avoid committing large amounts of memory - the cause of OOM problems in Oxlint with JS plugins on Windows (#19395).

Copy link
Copy Markdown
Member Author

overlookmotel commented May 2, 2026


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent changes, fast-track this PR to the front of the merge queue

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 2, 2026

Merging this PR will not alter performance

✅ 48 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing om/05-02-refactor_allocator_per-platform_arena_new_fixed_size_implementations (0bf0cb9) with main (d58f594)2

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (0bf0cb9) during the generation of this report, so d58f594 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@overlookmotel overlookmotel self-assigned this May 2, 2026
@overlookmotel overlookmotel marked this pull request as ready for review May 2, 2026 21:33
Copilot AI review requested due to automatic review settings May 2, 2026 21:33
@overlookmotel overlookmotel added C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior A-allocator Area - Allocator labels May 2, 2026
@overlookmotel overlookmotel changed the title refactor(allocator): per-platform Arena::new_fixed_size implementations perf(allocator): per-platform Arena::new_fixed_size implementations May 2, 2026
@overlookmotel overlookmotel added C-performance Category - Solution not expected to change functional behavior, only performance and removed C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels May 2, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors Arena::new_fixed_size into per-platform implementations to better handle very high alignment requirements (4 GiB) across macOS, Windows, and Linux, reducing unnecessary VM usage on Linux and avoiding Rust std’s Windows high-alignment workaround overhead.

Changes:

  • Introduces a new arena/fixed_size/ module with OS-specific Arena::new_fixed_size implementations (macos, windows, linux fallback).
  • Adjusts Windows fixed-size arena allocation to use a low-alignment backing allocation and manually select a 4 GiB-aligned sub-region.
  • Updates CI workflow job/step gating (currently by commenting out if: conditions).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/oxc_allocator/src/arena/fixed_size/mod.rs Adds shared docs/invariants and dispatches to platform-specific implementations via cfg.
crates/oxc_allocator/src/arena/fixed_size/macos.rs Uses 2 GiB-aligned over-allocation strategy to obtain a 4 GiB-aligned chunk on macOS.
crates/oxc_allocator/src/arena/fixed_size/windows.rs Uses a 16-byte-aligned over-allocation and manual pointer rounding to a 4 GiB boundary on Windows.
crates/oxc_allocator/src/arena/fixed_size/linux.rs Requests the desired BLOCK_SIZE + BLOCK_ALIGN directly (and acts as the non-macOS/non-Windows fallback).
.github/workflows/ci.yml Comments out multiple if: conditions, making many jobs/steps run unconditionally.
Comments suppressed due to low confidence (1)

crates/oxc_allocator/src/arena/fixed_size/macos.rs:63

  • The safety comment says “We allocated 4 GiB of memory”, but the actual allocation is ALLOC_SIZE = BLOCK_SIZE + TWO_GIB (4 GiB - 16). Since this is part of the unsafe reasoning, it should describe the precise size/in-bounds argument (or reference ALLOC_SIZE) to avoid future confusion.

Comment thread .github/workflows/ci.yml
Comment thread crates/oxc_allocator/src/arena/fixed_size/linux.rs Outdated
@overlookmotel overlookmotel force-pushed the om/05-02-refactor_allocator_per-platform_arena_new_fixed_size_implementations branch from 9aefd50 to a636cb8 Compare May 2, 2026 21:56
@overlookmotel overlookmotel force-pushed the om/05-02-refactor_allocator_remove_can_grow_field_from_arena_ branch 2 times, most recently from e0da555 to 6900042 Compare May 2, 2026 22:20
@overlookmotel overlookmotel force-pushed the om/05-02-refactor_allocator_per-platform_arena_new_fixed_size_implementations branch from a636cb8 to 40fa8b5 Compare May 2, 2026 22:20
@graphite-app
Copy link
Copy Markdown
Contributor

graphite-app Bot commented May 2, 2026

Merge activity

…#22088)

Introduce separate `Arena::new_fixed_size` implementations for different platforms.

Different platforms have differing abilities to service allocation requests with high alignment, so a different allocation strategy is appropriate for each:

- Mac OS: System allocator refuses 4 GiB-aligned allocation requests. Allocate ~4 GiB with 2 GiB alignment, then use either the top or bottom half for the arena chunk.
- Windows: System allocator cannot service allocations with any alignment over 16. Allocate ~6 GiB with 16 alignment, and then find a ~2 GiB block within that allocation which is aligned on 4 GiB. This is what `std` was doing already, but implementing it ourself sidesteps an annoyance with `std`'s implementation.
- Linux: System allocator can service high-alignment requests, so just ask for exactly what we want (~2 GiB with 4 GiB alignment).

This reduces virtual memory usage on Linux, side-steps `std`'s workaround on Windows, and is unchanged for Mac OS.

This also prepares the way for using `VirtualAlloc`\-based allocation on Windows, to avoid committing large amounts of memory - the cause of OOM problems in Oxlint with JS plugins on Windows (#19395).
@graphite-app graphite-app Bot force-pushed the om/05-02-refactor_allocator_remove_can_grow_field_from_arena_ branch from 6900042 to 94040ce Compare May 2, 2026 23:06
@graphite-app graphite-app Bot force-pushed the om/05-02-refactor_allocator_per-platform_arena_new_fixed_size_implementations branch from 40fa8b5 to 0bf0cb9 Compare May 2, 2026 23:06
Base automatically changed from om/05-02-refactor_allocator_remove_can_grow_field_from_arena_ to main May 2, 2026 23:10
@graphite-app graphite-app Bot merged commit 0bf0cb9 into main May 2, 2026
37 checks passed
@graphite-app graphite-app Bot deleted the om/05-02-refactor_allocator_per-platform_arena_new_fixed_size_implementations branch May 2, 2026 23:11
camc314 added a commit that referenced this pull request May 5, 2026
### 💥 BREAKING CHANGES

- 0ffbe0d allocator: [**BREAKING**] Remove `Allocator::end_ptr` method
(#21871) (overlookmotel)

### 🚀 Features

- 9593ec8 transformer/jsx: Add jsxDEV source metadata for fragments
(#21932) (Ido Rosenthal)

### 🐛 Bug Fixes

- 429deac napi/parser: Export `visitorKeys` from `wasm` entrypoint
(#21996) (NullVoxPopuli)
- e852911 codegen: Preserve legal comments orphaned by upstream passes
(#21575) (Dunqing)
- e3399ec transformer/class-properties: Preserve RHS in
logical-assignment to static private field (#21950) (Dunqing)
- c59c199 transformer/typescript: Emit class fields for parameter
properties (#21831) (Dunqing)
- aaabde4 parser: Attach legal comments to following token (#21670)
(Dunqing)

### ⚡ Performance

- 0bf0cb9 allocator: Per-platform `Arena::new_fixed_size`
implementations (#22088) (overlookmotel)

### 📚 Documentation

- 62ec410 allocator: Correct doc comment for `Allocator::from_raw_parts`
(#22093) (overlookmotel)
- 3e152c6 allocator: Correct typos in comments (#22092) (overlookmotel)
- e220855 allocator: Correct doc comment for `Allocator::set_cursor_ptr`
(#21866) (overlookmotel)

---------

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Co-authored-by: Cameron Clark <cameron.clark@hey.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-allocator Area - Allocator C-performance Category - Solution not expected to change functional behavior, only performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants