Skip to content

[RFC] support accumulator in cpgpass without API changes#1846

Closed
max-leuthaeuser wants to merge 3 commits intomasterfrom
max/accumulatorPassAlternative
Closed

[RFC] support accumulator in cpgpass without API changes#1846
max-leuthaeuser wants to merge 3 commits intomasterfrom
max/accumulatorPassAlternative

Conversation

@max-leuthaeuser
Copy link
Contributor

@max-leuthaeuser max-leuthaeuser commented Mar 12, 2026

Rewrote ForkJoinParallelCpgPassWithAccumulator to use the stream.collect(Supplier, BiConsumer, BiConsumer) API instead of ThreadLocal + ConcurrentLinkedQueue.

  1. Combined container (BuilderWithAccumulator): Pairs a DiffGraphBuilder with an accumulator R per fork. The Supplier creates one per thread, so both are naturally thread-local without explicit ThreadLocal management.
  2. Three stream.collect callbacks mirror ForkJoinParallelCpgPass:
    - Supplier: creates a fresh BuilderWithAccumulator(newDiffGraphBuilder, newAccumulator())
    - Accumulator BiConsumer: calls runOnPartWithAccumulator(bwa.builder, bwa.acc, part)
    - Combiner BiConsumer: absorbs the right builder into the left AND merges accumulators via mergeAccumulators
  3. Error handling preserved: Uses _accResult/_hasResult to store the merged accumulator. finish() calls onAccumulatorComplete with the merged result on success, or a fresh newAccumulator() on failure.
  4. Extends CpgPassBase directly instead of ForkJoinParallelCpgPass to avoid an unused/dead runOnPart method.

Hence: no API changes to the original ForkJoinParallelCpgPass, no null/Null, still using the pretty stream.collect(Supplier, BiConsumer, BiConsumer) API.
Downside: some code duplication. That's unavoidable if you don't want to change the existing API.

@max-leuthaeuser
Copy link
Contributor Author

I will create a new PR merging all the stuff we discussed.

@max-leuthaeuser max-leuthaeuser deleted the max/accumulatorPassAlternative branch March 12, 2026 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant