Skip to content

Make ArenaVec a Vec over a std Allocator - #332

Closed
kevaundray wants to merge 1 commit into
leanEthereum:riscv-explorationfrom
kevaundray:kw/allocator-api
Closed

kevaundray wants to merge 1 commit into
leanEthereum:riscv-explorationfrom
kevaundray:kw/allocator-api

Conversation

@kevaundray

@kevaundray kevaundray commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

This is an experiment to see what it would look like to adopt thw new allocator API that was standardised in nightly rust 1.100.

This is not meant to be merged, we can just wait for it to go onto stable.

The `Allocator` trait, `Vec<T, A>` and `Box<T, A>` are stable from Rust 1.100 (rust-lang/rust#156882). `zk_alloc::Arena` is a zero-sized `Allocator` over `raw_alloc`/`raw_dealloc`, which already tell arena from system memory by address, and `ArenaVec<T>` is `Vec<T, Arena>`. The hand-written vector is gone and every `Vec` method works on an `ArenaVec`.

- `Vec`'s constructors belong to the global allocator, so `new`, `with_capacity`, `from_slice`, `filled`, `zeroed`, `uninitialized` and `from_iter` move to an `ArenaVecExt` trait. `collect()`, `Default` and `mem::take` are unavailable for the same reason; four call sites use `from_iter` and `mem::replace` instead.
- `primitives::multilinear::Shrink` only let the folds take either vector type. It is deleted and the folds are generic over `A: Allocator`, calling `truncate` (not `Vec::shrink_to`, which shrinks capacity).
- An allocator's methods must never unwind. The address space was reserved lazily inside the first allocation behind an `assert!`; `enable_arena` now reserves it.
- `clippy::uninit_vec` now sees two deliberate uninitialized vectors it could not see through the old type; each gets an `#[expect]` with its reason.

Requires Rust 1.100 (nightly until it ships); stable 1.97 rejects `allocator_api`.

Measured on x86-64 (32 threads), same nightly for both builds, alternating runs, proving time:
fibonacci --n 2000000: base 1.864 s, 1.883 s; new 1.889 s, 1.923 s
leanxmss --n 400: base 3.247, 3.275, 3.152 (±7.2%) s; new 3.284, 3.244, 3.248 s
No difference beyond run-to-run noise; peak memory within 0.3%.
@kevaundray

Copy link
Copy Markdown
Collaborator Author

CI fails because its not using nightly-1.100

@kevaundray

Copy link
Copy Markdown
Collaborator Author

closing

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant