Skip to content

arena2: resolve per allocation overhead#61

Open
shruti2522 wants to merge 4 commits intoboa-dev:mainfrom
shruti2522:overhead
Open

arena2: resolve per allocation overhead#61
shruti2522 wants to merge 4 commits intoboa-dev:mainfrom
shruti2522:overhead

Conversation

@shruti2522
Copy link
Copy Markdown
Contributor

fix #58

converted ArenaHeapItem<T> into zero cost repr(transparent) wrapper by removing the extra 8 byte TaggedPtr header so only the GcBox header remains. Replaced O(n) linkedlist check for empty arenas with O(1) alloc_count == drop_count checks and moved mark_dropped to the allocator layer. Because objects no longer have hidden headers with raw pointers, we can now safely build features like compacting or generational GC
Also PoolItem already worked this way, so no changes made there

I have documented my findings in the notes

@shruti2522 shruti2522 closed this Mar 26, 2026
@shruti2522 shruti2522 deleted the overhead branch March 26, 2026 00:32
@boa-dev boa-dev deleted a comment from theAnuragMishra Mar 26, 2026
@boa-dev boa-dev deleted a comment from theAnuragMishra Mar 26, 2026
@boa-dev boa-dev deleted a comment from theAnuragMishra Mar 26, 2026
@boa-dev boa-dev deleted a comment from theAnuragMishra Mar 26, 2026
@boa-dev boa-dev deleted a comment from theAnuragMishra Mar 26, 2026
@nekevss
Copy link
Copy Markdown
Member

nekevss commented Mar 26, 2026

Why was this closed? I was still reviewing the changes

@shruti2522
Copy link
Copy Markdown
Contributor Author

Why was this closed? I was still reviewing the changes

There were a lot of spam comments on this one, so I thought I would open a new one

@shruti2522 shruti2522 restored the overhead branch March 26, 2026 00:55
@shruti2522 shruti2522 reopened this Mar 26, 2026
@shruti2522
Copy link
Copy Markdown
Contributor Author

Reopened it

@nekevss
Copy link
Copy Markdown
Member

nekevss commented Mar 26, 2026

Ah, yeah. I was planning on deleting those and cleaning up the PR. Sorry for the delay on that 😓

Definitely spam. A PR is not the place for any of that, especially on a repo like this one 🤣

Copy link
Copy Markdown
Member

@nekevss nekevss left a comment

Choose a reason for hiding this comment

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

Feedback is below!

Actually looking through this a bit deeper, I have a sinking feeling that we may not be able to condense the overhead until we change how we track roots.

There is a good chance that this would be fine in the context of our GC, but I don't know if I want to risk it without a way that I feel confident about proving.

Comment thread oscars/src/alloc/arena2/alloc.rs Outdated
drop_in_place(self.value_mut())
}
}
// With repr(transparent), the outer struct has the same address as the inner value
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should just remove this method. No point preserving two APIs that are returning *mut T

Comment thread oscars/src/alloc/arena2/alloc.rs Outdated
buf: NonNull<u8>, // Start of a byte buffer
}
#[repr(transparent)]
pub struct ErasedHeapItem(NonNull<u8>);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: preserve comment

Comment thread oscars/src/alloc/arena2/alloc.rs Outdated
impl<T> core::convert::AsRef<T> for ErasedHeapItem {
fn as_ref(&self) -> &T {
// SAFETY: TODO
// SAFETY: caller ensures this pointer was allocated as T
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"caller must ensure"

Comment thread oscars/src/alloc/arena2/alloc.rs Outdated
#[derive(Debug, Clone, Copy)]
#[repr(transparent)]
pub struct ErasedArenaPointer<'arena>(NonNull<ErasedHeapItem>, PhantomData<&'arena ()>);
pub struct ErasedArenaPointer<'arena>(NonNull<u8>, PhantomData<&'arena ()>);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

question: why not use ErasedHeapItem here?

I think I'd prefer to preserve the type for it's explicitness, but I'm open to this if you have a good argument for NonNull<u8>

Comment thread oscars/src/alloc/arena2/alloc.rs Outdated
pub layout: Layout,
pub last_allocation: Cell<*mut ErasedHeapItem>,
/// Number of allocations made in this arena
alloc_count: Cell<usize>,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

issue: I'm not sure this is the correct approach.

I think this approach does work, but I believe it would open us up to a pretty large issue where an already dropped allocation could be provided and then the drop count is immediately incorrect.

The allocation header / footer needs to be able to track its liveliness

@shruti2522
Copy link
Copy Markdown
Contributor Author

thanks for the review :)
This needs more thought, but yes liveness tracking is critical here. A bit occupied right now, but will revisit it tonight

@shruti2522 shruti2522 marked this pull request as draft April 1, 2026 09:07
@shruti2522 shruti2522 marked this pull request as ready for review April 2, 2026 23:46
@shruti2522 shruti2522 marked this pull request as draft April 3, 2026 00:00
@shruti2522 shruti2522 marked this pull request as ready for review April 3, 2026 01:30
@shruti2522
Copy link
Copy Markdown
Contributor Author

I have added a note analysing why we can't get rid of the overhead in arena2 without redesigning, reverted changes for now

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.

Resolve ArenaHeapItem / PoolItem and GcBox

2 participants