Onsen provides a hot Pool for objects. In most cases allocation from this Pool is faster and offers better locality than the standard allocator.
An onsen pool allocated 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 a very weak order and the entry point always point close to where the last action happend to keep the caches hot.
Onsen comes with its own Box and Rc/Weak implementations that wrap the underlying Pool in a safe way.
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.
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. The more expensive checks are only run in debug mode. Few things can not be asserted and are guarded by unsafe functions.
pool.leak()
which drops a pool while leaking its memory blocks. This can be
used when one will never try to free memory obtained from that Pool.&mut T
from a Slot is mutually exclusive to obtaining a Pin<&mut T>
.
slot.assume_init()
. This would break the Pin guarantees.
slot.get_uninit()
and slot.assume_init()
are
unsafe and must be enforced by the programmer.slot.into_u64()
, Slot::from_u64()
and Slot::from_u64_masked()
.Onsen uses criterion for benchmarking, since onsen is made for singlethreaded application its best to be tested when locked on a single CPU core (nowadays CPU cores have different performance characteristics). 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 $$
taskset 2 cargo bench
Will produce target/criterion/report/index.html
.