Skip to content

perf(mask): read intersect_by_rank rank bits at an absolute offset - #10480

Merged
robert3005 merged 1 commit into
vortex-data:developfrom
mightsleep:rank-bits
Oct 14, 2026
Merged

robert3005 merged 1 commit into
vortex-data:developfrom
mightsleep:rank-bits

Conversation

@mightsleep

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #10168 and #10456. RankBitReader pulled the rank bits through a two-word window over BitChunkIterator and 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 self chunk, so the rank offset of the next chunk is known without any reader state. RankBits reads 16 bytes at that offset and shifts by offset % 8, which covers any 64-bit read. There is one bounds check per read and no iterator, so RankBitReader and low_bits are 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 self the 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 three cmovs, which puts the comparisons in front of every load and costs dense masks 8 %.

Numbers

Zen 5, default build, perf stat over the kernel only: each bench runs with --sample-count 100 at --sample-size 200 and 400, 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.

before after
random_rotating, cycles 4894 M 4256 M 1.15x
random_rotating, instructions 17.9 G 15.8 G -12 %
sparse, cycles 3184 M 3110 M 1.02x

random_rotating and sparse are all their cases together, weighted by time.

Testing

kernels_match_reference now also slices the rank buffer at a bit offset (past_a_word, 67) so that a read starting past the first word is covered. Dropping start from RankBits::read fails four tests, ignoring tail_start fails five.

Signed-off-by: mightsleep <acannix@proton.me>
@robert3005 robert3005 added the changelog/performance A performance improvement label Oct 14, 2026
@codspeed

codspeed Bot commented Oct 14, 2026

Copy link
Copy Markdown

Merging this PR will regress 3 benchmarks

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

⚠️ 1 benchmark measured no execution time

Nothing ran under measurement, usually because the compiler removed the code under test. This result is not comparable, so it counts as unchanged.

Preventing compiler optimizations

⚠️ 10 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 14 improved benchmarks
❌ 3 regressed benchmarks
✅ 2196 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Simulation density_sweep_dense_runs[0.001] 29.6 µs 47.9 µs -38.23%
❌ WallTime bitpack_blocked_compress_avx512 4.8 µs 5.5 µs -12.84%
❌ WallTime bitpack_blocked_compress_avx2 6.7 µs 7.6 µs -11.24%
⚡ WallTime random_rotating_avx2[(0.9, 0.9, "self_90pct_mask_90pct")] 14.2 µs 8.3 µs +70.86%
⚡ WallTime random_rotating_avx512[(0.9, 0.9, "self_90pct_mask_90pct")] 13.8 µs 8.3 µs +66.61%
⚡ WallTime random_rotating_avx512[(0.5, 0.5, "self_50pct_mask_50pct")] 10.9 µs 8.2 µs +32.54%
⚡ WallTime random_rotating_avx2[(0.5, 0.5, "self_50pct_mask_50pct")] 10.8 µs 8.3 µs +30.87%
⚡ WallTime random_rotating_avx2[(0.1, 0.5, "self_10pct_mask_50pct")] 10.1 µs 8.3 µs +22.15%
⚡ WallTime random_rotating_avx512[(0.1, 0.5, "self_10pct_mask_50pct")] 10.2 µs 8.3 µs +21.89%
⚡ WallTime random_rotating_neon[(0.02, 0.5, "self_2pct_mask_50pct")] 24.8 µs 20.4 µs +21.7%
⚡ WallTime random_rotating_avx2[(0.05, 0.5, "self_5pct_mask_50pct")] 9.6 µs 8.3 µs +15.76%
⚡ WallTime random_rotating_neon[(0.05, 0.5, "self_5pct_mask_50pct")] 60.7 µs 53.2 µs +14.13%
⚡ WallTime random_rotating_neon[(0.9, 0.9, "self_90pct_mask_90pct")] 54.1 µs 47.5 µs +13.94%
⚡ WallTime threshold_avx512[8] 2 µs 1.8 µs +13.14%
⚡ WallTime random_rotating_neon[(0.1, 0.5, "self_10pct_mask_50pct")] 52.6 µs 47.3 µs +11.26%
⚡ WallTime random_rotating_avx512[(0.05, 0.5, "self_5pct_mask_50pct")] 9.2 µs 8.3 µs +11.23%
⚡ WallTime random_rotating_neon[(0.5, 0.5, "self_50pct_mask_50pct")] 52.8 µs 47.6 µs +10.9%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing mightsleep:rank-bits (72dd75d) with develop (58d0490)

Open in CodSpeed

@robert3005
robert3005 merged commit df8c104 into vortex-data:develop Oct 14, 2026
117 of 119 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/performance A performance improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants