pub struct KeyArena { /* private fields */ }Expand description
Thread-local arena allocator for key buffers
Provides O(1) bump-pointer allocation for temporary key data. Much faster than malloc for high-frequency allocations.
§Performance
- Bump allocation: ~3ns vs ~50ns for malloc
- No fragmentation within transaction scope
- Automatic reset between transactions
§Usage Pattern
ⓘ
KeyArena::with(|arena| {
let key1 = arena.alloc_key(b"table/123/column");
let key2 = arena.alloc_key(b"table/456/other");
// Use keys...
// Arena is automatically reused for next call
});Implementations§
Source§impl KeyArena
impl KeyArena
Sourcepub fn with_chunk_size(chunk_size: usize) -> Self
pub fn with_chunk_size(chunk_size: usize) -> Self
Create arena with custom chunk size
Sourcepub fn with<F, R>(f: F) -> R
pub fn with<F, R>(f: F) -> R
Access the thread-local arena
The callback receives a reference to the thread-local arena. This is the recommended API for arena access.
Sourcepub fn alloc_key<'a>(&'a self, data: &[u8]) -> ArenaKey<'a>
pub fn alloc_key<'a>(&'a self, data: &[u8]) -> ArenaKey<'a>
Allocate a key in the arena (bump allocation)
Returns an ArenaKey that references data in the arena. The returned key is valid until the arena is reset.
§Performance
- Fast path (fits in current chunk): ~3ns
- Slow path (new chunk needed): ~50ns + allocation
Sourcepub fn reset(&self)
pub fn reset(&self)
Reset the arena for reuse
This is O(1) - just resets the allocation pointers. Existing chunks are kept for reuse.
Sourcepub fn bytes_used(&self) -> usize
pub fn bytes_used(&self) -> usize
Get total bytes allocated since last reset
Sourcepub fn chunk_count(&self) -> usize
pub fn chunk_count(&self) -> usize
Get the number of chunks allocated
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for KeyArena
impl !RefUnwindSafe for KeyArena
impl Send for KeyArena
impl !Sync for KeyArena
impl Unpin for KeyArena
impl UnsafeUnpin for KeyArena
impl UnwindSafe for KeyArena
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more