feat: parallel v2 phase 2 — Ordered() via batch-aligned re-sequencing - #16
Merged
Merged
Conversation
…ncing New Streamer.Ordered(): marks a parallel section order-preserving. The feeder stamps indices, workers forward Filter-dropped elements as holes (keeping batch boundaries intact), and the consumer re-sequenences batch-keyed: aligned batches yield straight through, holes advance the expected index — no stalling on filtered gaps, no jumping ahead of in-flight batches. Design notes from the implementation journey: naive next-index map waits deadlock on holes; smallest-pending emits early under batch races; ring slots corrupt when in-flight distance exceeds the window (measured: consumer-held partial batches extend it); batch-keyed pending map with hole placeholders is the correct and fast structure. Acceptance (M3 Pro): A3 property test 30 random pipelines match serial element-for-element incl. adversarial batch-head filtering and all-filtered streams; ordered overhead on near-free work 2x serial (gate <=3x, was 8x with the naive map); heavy-load speedup unchanged 3.6x; short-circuit and cancellation lean. race/lint clean; coverage ~100% (one benign timing branch in orderedSeq closer occasionally uncovered).
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.
Summary
Phase 2 of
docs/proposals/parallel-v2.md:Ordered()— opt-in order preservation for parallel sections.How it works
Parallel(n).Ordered()...— feeder stamps input indices, workers forward Filter-dropped elements as holes (batch boundaries/lengths stay intact), consumer re-sequenences batch-keyed: an aligned batch yields straight through with zero per-element bookkeeping; holes advance the expected index.Ordered()without a parallel section is a no-op;Parallel(n)resets to unordered.Design journey (documented in the commit)
Three candidate re-sequencers were built and measured:
Acceptance (Apple M3 Pro)
Verification
go test ./... -racegreen; golangci-lint 0 issues