Skip to content

feat(arena2): implement dynamic alignment for ArenaAllocator #47

Merged
nekevss merged 2 commits intoboa-dev:mainfrom
shruti2522:min-align
Mar 14, 2026
Merged

feat(arena2): implement dynamic alignment for ArenaAllocator #47
nekevss merged 2 commits intoboa-dev:mainfrom
shruti2522:min-align

Conversation

@shruti2522
Copy link
Contributor

Replaced hardcoded arena alignment with dynamic type based alignment with min_alignment configuration (arena2)

/// Initialize a fresh arena.
pub fn initialize_new_arena(
&mut self,
required_alignment: usize,
Copy link
Member

Choose a reason for hiding this comment

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

issue: I think this should really just be a const parameter vs. a regular parameter.

Had you looked at using const parameters for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I looked into this, here's what I have found so far. One possible design would be to make MIN_ALIGN a const parameter on ArenaAllocator and compute max(MIN_ALIGN, ALIGN) when creating a new arena. Since both values would be const, the compiler could resolve max at compile time.

But I think this doesn’t really help here since arena_size is still a runtime value and Arena::try_init uses Layout::from_size_align(arena_size, alignment). Because the size is runtime, the layout cannot be fully computed at compile time anyway.

It would also mean many parts of the code would also need MIN_ALIGN as a generic parameter but that would involve a lot of changes without improving runtime performance. Also, instead of ArenaAllocator<'alloc>, we would need types like ArenaAllocator<'alloc, 8>, and allocators with different alignments would become incompatible types.

So I think the current design keeps the code simpler

@shruti2522 shruti2522 marked this pull request as draft March 13, 2026 14:01
@shruti2522 shruti2522 marked this pull request as ready for review March 13, 2026 16:59
@nekevss nekevss merged commit 8ae5d92 into boa-dev:main Mar 14, 2026
4 checks passed
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.

2 participants