Skip to content

arena2: resolve per allocation overhead#61

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

arena2: resolve per allocation overhead#61
shruti2522 wants to merge 2 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
Copy link
Copy Markdown
Contributor Author

I have been contributing to open source since 2 -3 years, when AI coding tools weren't even a thing, if you have any objections with my work you can review it (that's what people in open source do, right?), but I dont think it's the place to show your frustation, since I have been contributing to this repo continuously for the past month, and I guess any one is open to if you want to, the orgs have been announced for a month now, if you are really interested in a project and want to contribute, I don't think anything is stopping you from doing that. Also someone else's work doesn't put down yours

@shruti2522
Copy link
Copy Markdown
Contributor Author

i did, i saw your last merged pr and it's 100% like what i described: asking ai to find problems then fix it.

fyi, the optimizations in my last pr were based on running benchmarks in boa_gc and adding #[inline] to function calls, what appears ai like in this??

the noise surely is

I guess every developer is contributing through that noise, since times have changed, but you can't quit on something you love doing just because a lot of people are doing it, again I would say someone else's work doesn't put down yours

@shruti2522
Copy link
Copy Markdown
Contributor Author

shruti2522 commented Mar 25, 2026

this isnt even a Pr you linked, Really in 2025, are we really seeing the same profiles?? anyways I don't need to prove my work to you, if the maintainers have no objection with my work, I don't think your opinion matters, so best of luck I have a lot of work to do, I am not going engage with you anymore

@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.

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

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

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"

#[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>

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

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