fix: --runThreadN 1 ran on every core, not on one - #166
Open
BenjaminDEMAILLE wants to merge 2 commits into
Open
Conversation
The rayon global pool was configured only when `--runThreadN` was greater than 1. Skipping the build at 1 does not give one thread: it leaves rayon's default, which is one worker per logical core. So `--runThreadN 1` ran the whole machine. Measured on 200k reads, before: 2.44 s wall at **1300% CPU**. After: 26.23 s wall at 100% CPU. The old figure was not a fast single-threaded run, it was a sixteen-way run wearing the wrong flag. This matters beyond the flag reading falsely. A scheduler or a container given one CPU gets sixteen worker threads; on a shared machine the run oversubscribes every other job; and with a thread-caching allocator each of those threads keeps its own heap, which is the very cost the comment above this code says the pool sizing exists to avoid. It also means the project's thread-invariance checks were weaker than they read: the `--runThreadN 1` leg was not a one-thread leg. Verified now that it is one: records are byte-identical between 1 and 8 threads on 200k real reads, and byte-identical to the previous binary's output at `--runThreadN 1`. Only the `@PG` `CL:` line differs between thread counts, because it records the command line. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
BenjaminDEMAILLE
force-pushed
the
bd/fix-runthreadn-one
branch
from
July 30, 2026 18:08
f5c38df to
ea56450
Compare
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
--runThreadN 1ran on every logical core. One line, and it was hiding in plain sight.What was wrong
The rayon global pool was configured only when
--runThreadNwas greater than 1:Skipping the build at 1 does not give one thread. It leaves rayon's default, which is one worker per logical core. So the single value a user is most likely to pass when they mean "use one core" was the one value that used all of them.
Measured on 200 000 real reads, 16-core machine:
The old 2.44 s was not a fast single-threaded run. It was a sixteen-way run wearing the wrong flag, which is also why a scaling curve taken with it looked absurd:
--runThreadN 2was slower than--runThreadN 1, because 2 actually meant 2 and 1 meant 16.Why it matters beyond the flag reading falsely
--runThreadN 1leg that runs sixteen-wide is not a one-thread leg, so comparing it against--runThreadN 16compared sixteen against sixteen.Verification
Output-neutral, checked two ways on 200 000 real reads:
--runThreadN 1is byte-identical to the old binary at--runThreadN 1,--runThreadN 1and--runThreadN 8produce identical records. The only differing byte is in the@PGCL:line, which records the command line and therefore the thread count itself.That second check is the one the guard was preventing anyone from running. It passes.
With
--runThreadN 1now meaning one thread, the real scaling on this machine is 26.2 s at 1 thread against 2.42 s at 16, about 10.8×.Gate: 560 lib + 26 integration tests,
cargo clippy --all-targets -- -D warnings,cargo fmt --check, all green. No new dependency, no flag change, no output change.Related
Found while taking a thread-scaling curve for #167, which is why the numbers there are trustworthy only after this: with the bug in place
--runThreadN 2measured slower than--runThreadN 1, because 2 meant 2 and 1 meant sixteen. #168 carries the allocation measurements from the same session.