hawkw/sharded-slab

make index type `NonZeroUsize`

GallagherCommaJack opened this issue · 4 comments

It'd be nice to be able to have an Option<Key> which didn't take up more space than Key in memory.

hawkw commented

We could do this — it might be useful for the tracing-subscriber use-case, as well, where we're currently adding 1 to all indices because 0 is reserved.

However, 0 is a valid slab index. If we did this, we would either end up wasting one slot on thread 0's slab, or need to do some munging of indices ourselves to avoid that. This may be worth it, however.

Would it be reasonable to add an associated Key type to the Config trait, with the default being usize to allow for custom configs that use std::num::NonZeroUsize instead?

hawkw commented

@inanna-malick hmm, in theory, that could work! Could be worth experimenting with.

I have a sketch of what it might look like here - it's not quite complete (I don't quite understand everything that's going on around key generation & what would be required to skip 0 there) but it shows the approximate scope of the changes https://github.com/inanna-malick/sharded-slab/tree/associated-key-type