Repository navigation
perf(parallel): persistent helper pool for parallelFor; finer reduction partials - #31
Merged
Merged
Conversation
…ed runs + stealing; finer reduction partials Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ess table) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 7, 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.
Why
On POWER9 bare metal, a 2^20 dot ran slower on 8 cores (553–625 µs) than on 4 (212 µs), with 2.4 of 8 CPUs busy.
parallelForforked goroutines per call, and Go wakes parked threads one after another. Three schedulers that kept per-call goroutines were measured in v0.5.2 (experiment/parallel-for-scheduling); each fixed one worker count and broke another.Change
internal/kernels/pool.go(new). Up toGOMAXPROCS-1helper goroutines, started once. After a job they poll for 200 µs (spinWindow), then park;publishwakes the parked ones. The park/publish race is closed by announce-then-recheck: either the publisher sees the flag and sends a wake-up, or the helper takes the flag back. If another call holds the pool, the new call falls back to the old fork/join.parallelFor. The caller and the helpers each own a contiguous run of blocks, then steal what is left of the other runs. Block boundaries depend only on (n, w).mapReduceP,Dot1DP) use 4 partials per worker, each of at least 8192 elements. With one each, a helper that saw the job late lost its only block to the caller (Sum 4 Mi on 4 cores: 2.8 of 4 CPUs busy). The regrouping can changeSum/Dotby a few ULP compared with v0.5.2; results stay deterministic for a given GOMAXPROCS.Tests
TestPoolHelpersShareTheWorkasserts that blocks really run concurrently. A sabotagedpublishthat never wakes helpers fails it (peak concurrency 1); every other test would pass, because the caller does all the work.-raceand coverage at 100%.go vetpasses on linux amd64/ppc64le/loong64/386/arm/riscv64/s390x and on windows.Measured (POWER9 bare metal, one thread per core, each case in a fresh process, 6 interleaved rounds, median vs v0.5.2)
Behaviour
The helpers are never stopped, so goleak-style checks will list them. This is documented in the README (new Goroutines section) and in the package doc. They burn at most 200 µs of polling after each parallel operation.
Version: v0.6.0 (visible behaviour change; reduction regrouping).
🤖 Generated with Claude Code