He-Pin opened a new pull request, #3062:
URL: https://github.com/apache/pekko/pull/3062
### Motivation
The `PhasedFusingActorMaterializer` uses an `ArrayList` with O(n) linear
scan to resolve forward wires during graph materialization, and
`GraphStageIsland` uses a Scala `List` for `outConnections` which allocates
cons cells on every addition. Both create unnecessary overhead for complex
stream graphs.
### Modification
1. **forwardWires: ArrayList → HashMap** — Replace
`java.util.ArrayList[ForwardWire]` with `java.util.HashMap[Integer,
ForwardWire]` keyed by `toGlobalOffset`. Forward wire lookup in `wireIn` drops
from O(n) linear scan to O(1) `remove()`. Recording in `wireOut` uses `put()`
instead of `add()`.
2. **outConnections: Scala List → ArrayList** — Replace `List[Connection]`
(`::=` prepending) with `java.util.ArrayList[Connection]` (lazy-init).
Eliminates cons cell allocation and enables indexed iteration in
`onIslandReady()`.
3. **emptyOutSlots shared constant** — In `TraversalBuilder.atomic()`,
stages with no outlets now reuse a shared `Array.emptyIntArray` instead of
allocating `new Array[Int](0)` each time.
4. **New JMH benchmarks**:
- `MaterializerWiringBenchmark` — Measures materialization throughput for
linear pipelines, broadcast-merge (gradual and immediate), and imported flow
topologies at complexity levels 10/50/100/200.
- `AsyncBoundaryThroughputBenchmark` — Measures cross-island element
throughput with 1/3/10 async boundaries, establishing a baseline for future
BoundaryEvent optimizations.
### Result
Forward wire resolution drops from O(n) to O(1) per lookup. `outConnections`
avoids Scala List cons-cell overhead. Empty-outlet stages reuse a shared array.
New benchmarks provide regression coverage for these materialization code paths.
### Tests
- `sbt "stream-tests / Test / testOnly *MaterializerSpec *PhasedFusingSpec
*TraversalBuilderSpec"` — 30 tests passed
- `sbt "stream-tests / Test / testOnly *GraphInterpreterSpec
*ActorGraphInterpreterSpec"` — 112 tests passed
- `sbt "bench-jmh / compile"` — passed
### References
None - performance optimization identified through code review
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]