sharded-slab icon indicating copy to clipboard operation
sharded-slab copied to clipboard

make index type `NonZeroUsize`

Open GallagherCommaJack opened this issue 4 years ago • 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.

GallagherCommaJack avatar May 03 '20 06:05 GallagherCommaJack

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.

hawkw avatar May 03 '20 23:05 hawkw

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?

inanna-malick avatar Jul 05 '20 23:07 inanna-malick

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

hawkw avatar Jul 06 '20 00:07 hawkw

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

inanna-malick avatar Jul 12 '20 18:07 inanna-malick