hawkw / sharded-slab

a lock-free concurrent slab (experimental)
MIT License
269 stars 17 forks source link

Reduce pointer indirections #14

Open hawkw opened 4 years ago

hawkw commented 4 years ago

Currently, looking up an item in the slab requires dereferencing three to four Boxes: the box around the shard slice: https://github.com/hawkw/sharded-slab/blob/b16043361ef5cb74750b69f91f9dace15a40ee60/src/lib.rs#L202 the box around the page data slice (or slices, depending on the operation): https://github.com/hawkw/sharded-slab/blob/b16043361ef5cb74750b69f91f9dace15a40ee60/src/lib.rs#L244-L249 and the box around each page's slot slice: https://github.com/hawkw/sharded-slab/blob/b16043361ef5cb74750b69f91f9dace15a40ee60/src/page/mod.rs#L73

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.