sharded-slab
sharded-slab copied to clipboard
feat: Make use of the last bit in Tid
Previously Tid::LEN was set to MAX_SHARDS.trailing_zeros() + 1, and MAX_SHARDS was set to next_pow2(Self::MAX_THREADS - 1), which leads to several odd conbinations:
MAX_THREADS=128
MAX_SHARDS=128
Tid::LEN=8
7 bit is enough to encode 128 threads, as the thread id starts from 0
and ends with Tid::BITS, which makes the extra one bit redundant(I can't find the usage of it).
MAX_THREADS=129
MAX_SHARDS=128
Tid::LEN=8
As shards are indexed by Tid, number of shards shouldn't be less than number of threads.
Therefore, I changed the implementation:
Tid::LENnow equals toMAX_SHARDS.trailing_zeros()MAX_SHARDSnow equals tonext_pow2(Self::MAX_THREADS)DefaultConfig::MAX_THREADSwere doubled leveraging the released bit