feat(arena2): implement dynamic alignment for ArenaAllocator #47
feat(arena2): implement dynamic alignment for ArenaAllocator #47nekevss merged 2 commits intoboa-dev:mainfrom
Conversation
| /// Initialize a fresh arena. | ||
| pub fn initialize_new_arena( | ||
| &mut self, | ||
| required_alignment: usize, |
There was a problem hiding this comment.
issue: I think this should really just be a const parameter vs. a regular parameter.
Had you looked at using const parameters for this?
There was a problem hiding this comment.
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
Replaced hardcoded arena alignment with dynamic type based alignment with
min_alignmentconfiguration (arena2)