hawkw/sharded-slab

Reduce pointer indirections

hawkw opened this issue · 0 comments

hawkw commented

Currently, looking up an item in the slab requires dereferencing three to four Boxes: the box around the shard slice:

shards: Box<[Shard<T, C>]>,

the box around the page data slice (or slices, depending on the operation):

sharded-slab/src/lib.rs

Lines 244 to 249 in b160433

local: Box<[page::Local]>,
/// The shared state for each page in this shard.
///
/// This consists of the page's metadata (size, previous size), remote free
/// list, and a pointer to the actual array backing that page.
shared: Box<[page::Shared<T, C>]>,

and the box around each page's slot slice:
type Slots<T, C> = Box<[Slot<T, C>]>;

It would be good to reduce the number of dereferences. Ideally, we could use fixed size arrays, since the slab is configured at compile time; however, doing this nicely would require const generics. Alternatively, we could consider using DSTs for at least some of our structs. However, this would require manually managing our allocations, and would still require some boxing — it would take careful design to actually reduce derefs with DSTs.

Since a slab is (almost) always in an Arc in most use-cases, we might want to make the entire slab a DST, reducing at least one box...this could have ergonomic disadvantages though.