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
| Bucket | Min Size | Max Size |
|---|---|---|
| 0 | 0 B | 255 B |
| 1 | 256 B | 511 B |
| 2 | 512 B | 1023 B |
| 3 | 1 KiB | 2047 B |
| 4 | 2 KiB | 4095 B |
| 5 | 4 KiB | 8191 B |
| 6 | 8 KiB | 16383 B |
| 7 | 16 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§
- Pooled
Buffer - An owned, pool-tracked byte buffer.
- Tensor
Pool - Slab-based, thread-safe buffer pool for zero-copy Arrow IPC tensor operations.
- Tensor
Pool Config - Configuration for
TensorPool. - Tensor
Pool Snapshot - Plain-struct snapshot of
TensorPoolStats. - Tensor
Pool Stats - 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.