QueryArena

Struct QueryArena 

Source
pub struct QueryArena { /* private fields */ }

Implementations§

Source§

impl QueryArena

Source

pub const DEFAULT_CAPACITY: usize

Default arena size: 10MB

Based on TPC-H Q6 analysis:

  • 60K rows × 16 columns = 960K SqlValues
  • Intermediate results: ~2MB
  • Expression temporaries: ~1MB
  • Safety margin: 7MB
Source

pub fn with_capacity(bytes: usize) -> Self

Create a new arena with the specified capacity in bytes

§Arguments
  • bytes - Number of bytes to pre-allocate
§Example
use vibesql_executor::memory::QueryArena;

// 1MB arena
let arena = QueryArena::with_capacity(1024 * 1024);
Source

pub fn new() -> Self

Create a new arena with the default capacity (10MB)

§Example
use vibesql_executor::memory::QueryArena;

let arena = QueryArena::new();
Source

pub fn alloc<T>(&self, value: T) -> &T

Allocate a value in the arena

Returns a reference to the allocated value with lifetime tied to the arena.

§Performance

Allocation overhead: ~1ns (vs ~100ns for heap allocation)

§Panics

Panics if the arena is out of space. Use try_alloc for fallible allocation.

§Example
use vibesql_executor::memory::QueryArena;

let arena = QueryArena::new();
let x = arena.alloc(42i64);
let y = arena.alloc(3.5f64);

assert_eq!(*x, 42);
assert_eq!(*y, 3.5);
Source

pub fn alloc_slice<T>(&self, len: usize) -> &mut [MaybeUninit<T>]

Allocate a slice in the arena

Returns a mutable slice of MaybeUninit<T> with the specified length. Caller must initialize elements before assuming them to be initialized.

Using MaybeUninit ensures memory safety - uninitialized memory cannot be accidentally read or dropped, preventing undefined behavior.

§Performance

Allocation overhead: ~1ns + negligible bounds check

§Panics

Panics if the arena is out of space.

§Example
use std::mem::MaybeUninit;

use vibesql_executor::memory::QueryArena;

let arena = QueryArena::new();
let slice = arena.alloc_slice::<i32>(100);

// Initialize the slice
for i in 0..100 {
    slice[i] = MaybeUninit::new(i as i32);
}

// SAFETY: All elements have been initialized above
let initialized_slice =
    unsafe { std::slice::from_raw_parts(slice.as_ptr() as *const i32, slice.len()) };
assert_eq!(initialized_slice[50], 50);
Source

pub fn try_alloc<T>(&self, value: T) -> Option<&T>

Try to allocate a value in the arena

Returns None if the arena is out of space.

§Example
use vibesql_executor::memory::QueryArena;

let arena = QueryArena::with_capacity(64);

// This succeeds
assert!(arena.try_alloc(42i64).is_some());

// Eventually this fails (arena full)
let mut count = 0;
while arena.try_alloc(count).is_some() {
    count += 1;
}
Source

pub fn reset(&mut self)

Reset the arena, allowing it to be reused

This doesn’t deallocate the buffer, just resets the bump pointer. All previously allocated values are invalidated.

§Example
use vibesql_executor::memory::QueryArena;

let mut arena = QueryArena::new();

// Allocate some values (i64 = 8 bytes)
let x = arena.alloc(42i64);
assert_eq!(arena.used_bytes(), 8);

// Reset and reuse
arena.reset();
assert_eq!(arena.used_bytes(), 0);

// Can allocate again
let y = arena.alloc(100i64);
Source

pub fn used_bytes(&self) -> usize

Get the number of bytes used in this arena

§Example
use vibesql_executor::memory::QueryArena;

let arena = QueryArena::new();

arena.alloc(42i64); // 8 bytes
arena.alloc(3.5f64); // 8 bytes

assert_eq!(arena.used_bytes(), 16);
Source

pub fn capacity_bytes(&self) -> usize

Get the total capacity of this arena in bytes

§Example
use vibesql_executor::memory::QueryArena;

let arena = QueryArena::with_capacity(1024);
assert_eq!(arena.capacity_bytes(), 1024);
Source

pub fn remaining_bytes(&self) -> usize

Get the number of bytes remaining in this arena

§Example
use vibesql_executor::memory::QueryArena;

let arena = QueryArena::with_capacity(1024);
arena.alloc(42i64); // 8 bytes

assert_eq!(arena.remaining_bytes(), 1024 - 8);

Trait Implementations§

Source§

impl Default for QueryArena

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for QueryArena

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for QueryArena

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool