shuffle: conformance test, GOMAXPROCS-aware fan-out, fork-join cleanup#787
Merged
Conversation
- Add a spec-conformance test checking computeShuffledList against the per-index computeShuffledIndex reference across sizes spanning the parallelization threshold, plus a mainnet-scale benchmark. - Size the worker fan-out by runtime.GOMAXPROCS(0) instead of NumCPU so container CPU quotas and user overrides are respected. - Use wg.Go and a start-stepped chunk loop; drop the dead unused-import guard. A persistent channel-fed worker pool (spawn once, signal per round) was also evaluated: it measured 2-4% slower than per-round goroutine spawns because workers park during the serial source-hash phase between rounds and channel wakeups cost more than fresh spawns. Documented in a comment on shuffleRound.
pk910
approved these changes
Jul 8, 2026
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.
Follow-up on #782, targeting
pk910/statetransition-performance.What's included
computeShuffledListagainst the per-indexcomputeShuffledIndexreference, across sizes spanning the 4096 parallelization threshold (0–20,000). Passes under-race. Also adds a mainnet-scale (1M indices) benchmark. The package previously had no tests for the shuffle.runtime.GOMAXPROCS(0)instead ofruntime.NumCPU()for the worker fan-out: NumCPU reports host cores and ignores container CPU quotas and user-set GOMAXPROCS, so the old code oversubscribes in quota'd containers.wg.Go(Go 1.25+) and a start-stepped chunk loop replace the manualAdd/Done+ bounds-clamping dance. Removed the deadvar _ = binary.LittleEndianguard.What's deliberately NOT included
A persistent channel-fed worker pool (spawn goroutines once, signal each of the 90 rounds over channels) was implemented and benchmarked as an alternative to per-round goroutine spawning. On the real workload it measured 2–4% slower in every interleaved run pair (mean 147.2 ms vs 142.5 ms per 1M-index shuffle, 16 threads):
The serial source-hash phase between rounds parks the pool workers, and waking 16 parked goroutines via sequential channel sends costs more than spawning fresh ones (the runtime hands new goroutines straight to idle Ps and recycles stacks). A synthetic benchmark without the inter-round serial phase shows the opposite (~10% pool win), which is why this needed measuring on the real code path. Documented in a comment on
shuffleRoundso it isn't re-attempted.Benchmark on this branch matches the base branch: ~122–129 ms per full shuffle (AMD 7840U, 8C/16T), ~6.3× over serial.