Skip to main content

TensorPool

Struct TensorPool 

Source
pub struct TensorPool { /* private fields */ }
Expand description

Slab-based, thread-safe buffer pool for zero-copy Arrow IPC tensor operations.

Internally maintains 8 free lists — one per power-of-two size class from 256 B to 32 MiB. All free lists are protected by individual Mutex locks so contention is minimised.

§Thread Safety

TensorPool is Send + Sync and can be wrapped in an Arc for sharing across threads / async tasks.

Implementations§

Source§

impl TensorPool

Source

pub fn new(config: TensorPoolConfig) -> Self

Create a new TensorPool with the supplied configuration.

Source

pub fn acquire(&self, min_bytes: usize) -> PooledBuffer

Acquire a buffer whose capacity is at least min_bytes.

If the corresponding free list is non-empty, a buffer is popped and returned (incrementing total_reuses). Otherwise a fresh Vec<u8> is allocated (incrementing total_allocs).

In both cases total_acquired is incremented.

Source

pub fn release(&self, buf: PooledBuffer)

Release a buffer back into the pool.

The buffer contents are cleared (length reset to 0, capacity retained) before being added to the free list. If the free list for the buffer’s bucket already holds max_per_bucket entries, the buffer is simply dropped (freeing its memory).

Increments total_released in both cases. Adjusts total_bytes_pooled by the buffer’s capacity when it is successfully pooled.

Source

pub fn pool_depth(&self, bucket: usize) -> usize

Return the number of free (available) buffers in the specified bucket.

§Panics

Panics in debug mode if bucket >= NUM_BUCKETS.

Source

pub fn stats(&self) -> TensorPoolSnapshot

Capture a snapshot of the pool statistics.

Source

pub fn prune(&self, max_per_bucket: usize)

Drain excess buffers from every bucket, keeping at most max_per_bucket buffers per bucket.

Buffers that are drained are dropped, releasing their memory. The total_bytes_pooled counter is decremented accordingly.

Trait Implementations§

Source§

impl Default for TensorPool

Source§

fn default() -> Self

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

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more