Skip to main content

Module tensor_pool

Module tensor_pool 

Source
Expand description

Slab-based Reusable Buffer Pool for Arrow IPC Zero-Copy Tensor Operations

This module provides a TensorPool — a production-grade, thread-safe buffer pool organized into power-of-two size buckets. It is designed for zero-copy Arrow IPC tensor operations where repeated allocation/deallocation of large byte buffers is a key performance bottleneck.

§Size Classes

BucketMin SizeMax Size
00 B255 B
1256 B511 B
2512 B1023 B
31 KiB2047 B
42 KiB4095 B
54 KiB8191 B
68 KiB16383 B
716 KiB

§Example

use ipfrs_tensorlogic::tensor_pool::{TensorPool, TensorPoolConfig};

let pool = TensorPool::new(TensorPoolConfig::default());

// Acquire a buffer that fits at least 1000 bytes
let mut buf = pool.acquire(1000);
buf.resize(1000, 0u8);
assert_eq!(buf.len(), 1000);

// Return buffer to pool
pool.release(buf);

// Next acquire should reuse the buffer
let buf2 = pool.acquire(1000);
let snap = pool.stats();
assert_eq!(snap.total_reuses, 1);
pool.release(buf2);

Structs§

PooledBuffer
An owned, pool-tracked byte buffer.
TensorPool
Slab-based, thread-safe buffer pool for zero-copy Arrow IPC tensor operations.
TensorPoolConfig
Configuration for TensorPool.
TensorPoolSnapshot
Plain-struct snapshot of TensorPoolStats.
TensorPoolStats
Atomic counters tracking pool activity.

Constants§

BUCKET_7_THRESHOLD
Size threshold above which everything is routed to bucket 7 (32 MiB).
NUM_BUCKETS
Number of buckets (power-of-two size classes)

Functions§

bucket_for
Returns the bucket index (0..=7) for a given size.