refactor(allocator/vec2): move len field from Vec to RawVec#10883
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via 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. |
882a193 to
b762280
Compare
CodSpeed Instrumentation Performance ReportMerging #10883 will not alter performanceComparing Summary
|
|
Now I understand what you're doing. However, it's rather complicated! I expect the perf regression is coming from the It's tricky, because we ideally want to maintain the separation between I can see 3 alternative approaches:
|
|
On second thoughts, forget everything I've said about Probably just moving If |
|
We should add a |
b6ac6d6 to
bed3f47
Compare
b762280 to
b0b67b2
Compare
d9f3c2a to
c6b2c72
Compare
RawVec fields to Veclen field from Vec to RawVec
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the memory layout of the allocator’s Vec and RawVec types in preparation for reducing field sizes. The changes include updating field offsets in the raw transfer generator, moving the len field from Vec to RawVec with corresponding constructor updates, and adjusting Vec methods to reference the new buf.len field.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tasks/ast_tools/src/generators/raw_transfer.rs | Updated the Vec field offset constant and comment to reflect the new layout. |
| crates/oxc_allocator/src/vec2/raw_vec.rs | Added the len field to RawVec and updated its constructors. |
| crates/oxc_allocator/src/vec2/mod.rs | Removed the len field from Vec and modified methods to use buf.len. |
Comments suppressed due to low confidence (1)
tasks/ast_tools/src/generators/raw_transfer.rs:30
- Ensure that the new VEC_LEN_FIELD_OFFSET value is valid on all targeted platforms given the revised memory layout of Vec and RawVec; adding a clarifying comment about this assumption might be helpful.
const VEC_LEN_FIELD_OFFSET: usize = 8;
All of |
c6b2c72 to
103e4e9
Compare
|
There should be no perf impact from moving But to test that assumption (and make sure we're not getting false results from CodSpeed on either/both of these PRs), I suggest re-ordering the fields of #[repr(C)]
pub struct RawVec<'a, T> {
ptr: NonNull<T>,
a: &'a Bump,
cap: usize,
pub(super) len: usize,
}This is the same order the fields were in before this PR (with default const _: () = {
use std::mem::offset_of;
assert!(size_of::<Vec<u8>>() == 32);
assert!(align_of::<Vec<u8>>() == 8);
assert!(offset_of!(Vec<u8>, buf) == 0);
assert!(offset_of!(Vec<u8>, len) == 24);
};
const _: () = {
use std::mem::offset_of;
assert!(size_of::<RawVec<u8>>() == 24);
assert!(align_of::<RawVec<u8>>() == 8);
assert!(offset_of!(RawVec<u8>, ptr) == 0);
assert!(offset_of!(RawVec<u8>, a) == 8);
assert!(offset_of!(RawVec<u8>, cap) == 16);
};Those assertions all pass on main branch. If you re-arrange After that change, this PR should have zero perf impact. If it still does, something is wrong. |
85a8b52 to
4b8e48e
Compare
4b8e48e to
085273f
Compare
085273f to
91cad19
Compare
|
CI got stuck (as usual!). I've rebased on main, fixed the raw transfer test failure, and force pushed (ditto for #10884). |
Merge activity
|
…0883) Prepare for #9706. Move `len` field from `Vec` to `RawVec` to adapt upcoming change that reduces `len` and `cap` fields from `usize` to `u32` so that the `Vec` size can reduce from `32` to `24` without padding. Marked `Vec` as `#[repr(transparent)]` and `RawVec` as `#[repr(C)]` to easier to solve raw transfer test failures because the fields are no longer reordered, we can statically determine the offsets, as mentioned in that comment.
91cad19 to
7d54577
Compare

Prepare for #9706.
Move
lenfield fromVectoRawVecto adapt upcoming change that reduceslenandcapfields fromusizetou32so that theVecsize can reduce from32to24without padding.Marked
Vecas#[repr(transparent)]andRawVecas#[repr(C)]to easier to solve raw transfer test failures because the fields are no longer reordered, we can statically determine the offsets, as mentioned in that comment.