Skip to content

refactor(allocator): remove sentinel empty chunk#21775

Merged
graphite-app[bot] merged 1 commit intomainfrom
om/04-26-refactor_allocator_remove_sentinel_empty_chunk
Apr 26, 2026
Merged

refactor(allocator): remove sentinel empty chunk#21775
graphite-app[bot] merged 1 commit intomainfrom
om/04-26-refactor_allocator_remove_sentinel_empty_chunk

Conversation

@overlookmotel
Copy link
Copy Markdown
Member

@overlookmotel overlookmotel commented Apr 26, 2026

The chunks in an Arena form a linked list. Previously the list was terminated with a canonical empty chunk, defined as a static.

Now that we store start_ptr and cursor_ptr in Arena itself (#21483), an empty Arena doesn't need to have a pointer to a chunk.

Remove the empty chunk, and use None to signify the end of the linked list instead.

This makes checking "is this chunk the last?" a little cheaper (comparison to 0, not a 64-bit static value), and feels less hacky, and more explicit. It also removes the potential hazard of accidentally mutating the immutable static empty chunk.

Copy link
Copy Markdown
Member Author

overlookmotel commented Apr 26, 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 Apr 26, 2026

Merging this PR will not alter performance

✅ 48 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing om/04-26-refactor_allocator_remove_sentinel_empty_chunk (f9ba289) with om/04-26-fix_linter_add_checks_that_program_is_in_current_allocator_chunk_before_js_plugins_linting (33f5535)

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.

@overlookmotel overlookmotel marked this pull request as ready for review April 26, 2026 12:12
Copilot AI review requested due to automatic review settings April 26, 2026 12:12
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 oxc_allocator::arena::Arena’s chunk linked-list termination from a static sentinel footer to Option<NonNull<ChunkFooter>>, making an empty arena explicitly represented by None and using a dangling aligned pointer for start_ptr/cursor_ptr in the empty state.

Changes:

  • Replaces the static empty chunk sentinel with None-terminated chunk links (current_chunk_footer_ptr and previous_chunk_footer_ptr become Option).
  • Introduces EMPTY_ARENA_DATA_PTR as the empty-arena sentinel for start_ptr/cursor_ptr and adjusts constructors/iterators/drop/reset accordingly.
  • Updates raw-parts helpers and tests to work with the new Option-based representation.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
crates/oxc_allocator/src/arena/tests_alloc.rs Updates test arena construction to use Some(footer_ptr) for the current chunk.
crates/oxc_allocator/src/arena/mod.rs Changes Arena and ChunkFooter pointer fields to Option, removes the static empty footer, adds EMPTY_ARENA_DATA_PTR.
crates/oxc_allocator/src/arena/from_raw_parts.rs Adjusts raw-parts initialization and pointer accessors for Option footer pointers and empty-arena behavior.
crates/oxc_allocator/src/arena/drop.rs Updates reset/drop chunk traversal and deallocation to stop at None rather than a sentinel footer.
crates/oxc_allocator/src/arena/create.rs Refactors new_impl/new_chunk APIs for the new representation and updates constructors.
crates/oxc_allocator/src/arena/chunks.rs Updates accounting and iterators to traverse until None and changes iterator state to Option.
crates/oxc_allocator/src/arena/alloc_impl.rs Updates slow-path chunk growth and retirement logic to handle empty arenas (None) safely.

Comment thread crates/oxc_allocator/src/arena/chunks.rs
Comment thread crates/oxc_allocator/src/arena/mod.rs Outdated
Comment thread crates/oxc_allocator/src/arena/create.rs
@overlookmotel overlookmotel force-pushed the om/04-26-refactor_allocator_remove_sentinel_empty_chunk branch 2 times, most recently from 7e57e6e to f37bdbc Compare April 26, 2026 20:47
@overlookmotel overlookmotel force-pushed the om/04-26-fix_linter_add_checks_that_program_is_in_current_allocator_chunk_before_js_plugins_linting branch from dac3cb8 to c3cb15b Compare April 26, 2026 20:47
@graphite-app
Copy link
Copy Markdown
Contributor

graphite-app Bot commented Apr 26, 2026

Merge activity

The chunks in an `Arena` form a linked list. Previously the list was terminated with a canonical empty chunk, defined as a `static`.

Now that we store `start_ptr` and `cursor_ptr` in `Arena` itself (#21483), an empty `Arena` doesn't need to have a pointer to a chunk.

Remove the empty chunk, and use `None` to signify the end of the linked list instead.

This makes checking "is this chunk the last?" a little cheaper (comparison to 0, not a 64-bit static value), and feels less hacky, and more explicit. It also removes the potential hazard of accidentally mutating the immutable `static` empty chunk.
@graphite-app graphite-app Bot force-pushed the om/04-26-fix_linter_add_checks_that_program_is_in_current_allocator_chunk_before_js_plugins_linting branch from c3cb15b to 33f5535 Compare April 26, 2026 21:50
@graphite-app graphite-app Bot requested a review from camc314 as a code owner April 26, 2026 21:50
@graphite-app graphite-app Bot force-pushed the om/04-26-refactor_allocator_remove_sentinel_empty_chunk branch from f37bdbc to f9ba289 Compare April 26, 2026 21:50
Base automatically changed from om/04-26-fix_linter_add_checks_that_program_is_in_current_allocator_chunk_before_js_plugins_linting to main April 26, 2026 22:05
@graphite-app graphite-app Bot merged commit f9ba289 into main Apr 26, 2026
38 checks passed
@graphite-app graphite-app Bot deleted the om/04-26-refactor_allocator_remove_sentinel_empty_chunk branch April 26, 2026 22:06
@overlookmotel overlookmotel added C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior A-allocator Area - Allocator labels Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-allocator Area - Allocator C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants