Description

Onsen provides hot Pools for objects. In most cases allocation from such a Pool is faster and offers better locality than the standard allocator. For small to medium sized objects the performance improvement is around 20% or better. For large objects the gains become smaller as caching effects even out. These improvements cover operating on objects because of locality, not just faster allocation speeds.

Details

Onsen pools allocate blocks with exponentially growing sizes. Allocations are served from these blocks. Freed entries are kept in a double linked cyclic freelist. This freelist is kept in weakly ordered and the entry point always point close to where the last action happend to keep the caches hot.

Box, Rc and Sc

Onsen comes with its own Box and Rc/Weak implementations that wrap the underlying RcPool in a safe way. A Sc reference counted box without weak reference support is available as well and provides an advantage for small objects where the weak count would add some weight.

For each of these a variant that uses static global pools is avaialble as well.

Slots

Allocating from a pool returns Slot handles. These are lightweight abstractions to memory addresses, they do not keep a relation to the pool they are allocated from. The rationale for this design is to make them usable in a VM that uses NaN tagging.

Slot Policies

Slots are guarded by typestate policies which prevent some wrong use at compile time.

Slots and Safety

Because of this slots need to be handled with care and certain contracts need to be enforced. The library provides some help to ensure correctness. Few things can not be asserted and are guarded by unsafe functions. Higher level API's (Such as Box, Rc and Sc above) can easily enforce these in a safe way.

  1. Slots must be given back to the pool they originate from.
  2. Slots must not outlive the pool they are allocated from.
  3. Slots must be freed only once.
  4. References obtained from slots must not outlive the freeing of the Slot.

Features

Onsen provides a singlethreaded Pool, a singlethreaded reference counted RcPool and a multithreaded TPool. Additional features are gated with feature flags.

st_tbox is the default. This enables the most complete API with best performance.

Performance Characteristics

Benchmarking

Onsen uses criterion for benchmarking, since onsen is made for singlethreaded application its best to be tested when locked on a single CPU core and lock the core to some frequency well below the max to give more consistent results. At higher priority so it wont be disturbed as much from other programs. On Linux you may do something like:

shell,ignore sudo renice -15 $$ sudo cpupower -c 1 frequenc-set -f 2.8GHz taskset 2 cargo bench

Will produce target/criterion/report/index.html.