Expand description

A thread-safe object pool collection with automatic return.

Some implementations are lockfree :

Other use std::Mutex :

And NoneObjectPool basic allocation without pool.

§Example

The general pool creation looks like this for

  use lockfree_object_pool::LinearObjectPool;
   
  let pool = LinearObjectPool::<u32>::new(
    ||  Default::default(),
    |v| {*v = 0; });

  // And use the object pool
  let mut item = pool.pull();
  *item = 5;

At the end of the scope item return in object pool.

§Multithreading

All implementation support allocation/desallocation from on or more thread. You only need to wrap the pool in a std::sync::Arc :

  use lockfree_object_pool::LinearObjectPool;
  use std::sync::Arc;

  let pool = Arc::new(LinearObjectPool::<u32>::new(
       ||  Default::default(),
       |v| {*v = 0; }));

§Performance

Global report.

§Allocation
ObjectPoolDuration in Monothreading (us)Duration Multithreading (us)
NoneObjectPool1.28480.62509
MutexObjectPool1.31071.5178
SpinLockObjectPool1.31061.3684
LinearObjectPool0.237320.38913
[crate 'sharded-slab']1.62640.82607
[crate 'object-pool']0.775330.26224

Report monothreading and multithreading

§Forward Message between Thread
ObjectPool1 Reader - 1 Writter (ns)5 Reader - 1 Writter (ns)1 Reader - 5 Writter (ns)5 Reader - 5 Writter (ns)
NoneObjectPool529.75290.47926.05722.35
MutexObjectPool429.29207.17909.88409.99
SpinLockObjectPool34.277182.621089.7483.81
LinearObjectPool43.876163.18365.56326.92
[crate 'sharded-slab']525.82775.79966.871289.2

Not supported by [crate 'object-pool']

Report 1-1, 5-1, 1-5 , 5-5

§Desallocation
ObjectPoolDuration in Monothreading (ns)Duration Multithreading (ns)
NoneObjectPool111.8193.585
MutexObjectPool26.108101.86
SpinLockObjectPool22.44150.107
LinearObjectPool7.537941.707
[crate 'sharded-slab']7.039410.283
[crate 'object-pool']20.51744.798

Report monothreading and multithreading

Structs§