perf(encoding): precompute FastLanes transpose/iterate index tables#138
Merged
Conversation
transposeIndex and iterateIndex computed per-element % / / plus an ORDER[] indirection. In the delta transpose and (un)delta hot loops that dependency chain (div -> ORDER load -> mul) serializes scatter address generation, throttling how many scatter misses stay in flight. Replace with permutation tables built once in a static initializer: - TRANSPOSE[CHUNK] for transposeIndex - ITERATE_BASE[64] for iterateIndex (lane added per call) Public API unchanged. JMH (Apple M5, long[], FastLanesTransposeBenchmark) across L1 -> DRAM working sets: - transpose: 3.4x (L1) ... 1.7x (256 MB) - undelta: 1.6x (L1) ... 1.4x (256 MB) Win persists when memory-bound: same dst indices = same traffic, so the gain is memory-level parallelism, not bandwidth. Shift-reduction control variants in the benchmark show strength reduction alone recovers only part of it (~1.5x transpose, ~1.08x undelta) - the dominant cost is the dependent ORDER[] load, which only the table removes. Also drops the now-completed FastLanes optimization item from TODO.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
8623487 to
ecd34bb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
FastLanes.transposeIndexanditerateIndexcomputed%//plus anORDER[]indirection per element. In the delta transpose and (un)delta hot loops that dependency chain (div → ORDER load → mul) serializes scatter address generation, throttling how many scatter misses stay in flight.Replaced with permutation tables built once in a static initializer:
TRANSPOSE[CHUNK]fortransposeIndexITERATE_BASE[64]foriterateIndex(lane added per call)Public API unchanged.
Why it's a real win (not just op-count)
Both loops are gather/scatter permutations (or have a serial
prevdependency), so they don't auto-vectorize and C2 already strength-reduces the power-of-two division. The measured gain is memory-level parallelism: same destination indices ⇒ identical memory traffic, so faster address generation simply keeps more outstanding scatter misses in flight. That's why the speedup persists even at 256 MB working sets.Benchmark
New
FastLanesTransposeBenchmark(Apple M5,long[], working set 8 KB → 256 MB):Run:
./bench FastLanesTransposeBenchmarkVerification
DeltaEncodingDecoderTest(11),DeltaEncodingEncoderTest(75),DeltaEncodingTest(10),RoundTripPropertyTest(408) — all passjavadoc:javadoc -pl core— clean🤖 Generated with Claude Code