Repository navigation
perf(mask): read intersect_by_rank rank bits at an absolute offset - #10480
Conversation
Signed-off-by: mightsleep <acannix@proton.me>
Merging this PR will regress 3 benchmarks
|
Signed-off-by: mightsleep <acannix@proton.me>
Merging this PR will regress 3 benchmarks
|
Summary
Follow-up to #10168 and #10456.
RankBitReaderpulled the rank bits through a two-word window overBitChunkIteratorand refilled it behind a branch on every 64 bits consumed. With random masks that branch mispredicts often.The kernel already counts the set bits of each
selfchunk, so the rank offset of the next chunk is known without any reader state.RankBitsreads 16 bytes at that offset and shifts byoffset % 8, which covers any 64-bit read. There is one bounds check per read and no iterator, soRankBitReaderandlow_bitsare gone. This applies to every deposit (BMI2, SVE2 BDEP, portable), not just one path.Reads near the end of the buffer come from a copy of its last 16 bytes followed by zeros, made once per call. With a sparse
selfthe last 128 rank bits cover many chunks: at 1/64 density that is about 120 of them. A first version copied the tail on each such read in a#[cold]function, and the call made the whole loop spill to the stack, so sparse masks ran 5 % slower than before.cold_path()keeps the branch: without it LLVM picks the address with threecmovs, which puts the comparisons in front of every load and costs dense masks 8 %.Numbers
Zen 5, default build,
perf statover the kernel only: each bench runs with--sample-count 100at--sample-size 200and400, and the difference between the two runs is the cost of 100 x 200 calls with the setup subtracted out. Wall-clock medians on this machine moved by up to 1.4x between processes of the same binary, so I'm not quoting them.random_rotating, cyclesrandom_rotating, instructionssparse, cyclesrandom_rotatingandsparseare all their cases together, weighted by time.Testing
kernels_match_referencenow also slices the rank buffer at a bit offset (past_a_word, 67) so that a read starting past the first word is covered. DroppingstartfromRankBits::readfails four tests, ignoringtail_startfails five.