pub struct GenericPool<T: Poolable + Clone> { /* private fields */ }Expand description
Generic high-performance object pool optimized for HFT latency requirements
Provides sub-microsecond object borrowing/returning through pre-allocation and recycling.
Uses parking_lot::RwLock for thread safety with read-optimized concurrency patterns.
§Design Trade-offs
- RwLock vs Lock-free: RwLock chosen for simplicity and good read concurrency
- SmallVec optimization: Stack allocation for small pools, heap expansion when needed
- Generic constraints:
Poolable + Cloneensures safe reuse patterns - Statistics tracking: Built-in monitoring with nanosecond-precision timing
§Performance Profile
- Borrow latency: 5-20ns typical (RwLock read + SmallVec pop)
- Return latency: 10-30ns typical (reset + RwLock write + SmallVec push)
- Concurrency: Multiple concurrent borrowers, serialized returns
- Memory footprint: Configurable capacity with pre-allocation
Implementations§
Source§impl<T: Poolable + Clone> GenericPool<T>
impl<T: Poolable + Clone> GenericPool<T>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a new object pool with specified capacity
Sourcepub fn borrow(&self) -> T
pub fn borrow(&self) -> T
Borrow an object from the pool
Returns a pre-allocated object that can be configured for use. If pool is empty, allocates a new object (tracked in stats).
Sourcepub fn return_object(&self, object: T)
pub fn return_object(&self, object: T)
Return an object to the pool for reuse
The object will be available for future borrowing. If pool is full, the object is dropped (no memory leak).
Sourcepub fn reset_stats(&self)
pub fn reset_stats(&self)
Reset pool statistics
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for GenericPool<T>
impl<T> !RefUnwindSafe for GenericPool<T>
impl<T> Send for GenericPool<T>
impl<T> Sync for GenericPool<T>
impl<T> Unpin for GenericPool<T>
impl<T> !UnwindSafe for GenericPool<T>
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