Add Stream type-pollution benchmark and guidance#3333
Open
He-Pin wants to merge 1 commit into
Open
Conversation
Motivation: Affected JDKs can lose throughput when the same stream element crosses alternating interface-typed non-inlined operators. The initial issue analysis attributed this to the fused Connection slot without runtime evidence. Modification: Add a fused-stream JMH comparison for concrete, stable-interface, and alternating-interface chains. Add a directional Flow map test and document the verified JVM upgrade and profiling guidance. Result: The benchmark reproduces the issue on JDK 17 while showing that JDK 21.0.8 removes the penalty, avoiding an unnecessary change to the core Stream interpreter hot path. Tests: - stream-tests / Test / testOnly org.apache.pekko.stream.scaladsl.FlowMapSpec - bench-jmh / Jmh / compile - docs/paradox - +headerCheckAll - checkCodeStyle - validatePullRequest (Stream tests passed; pre-existing jdocs.stream.IntegrationDocTest mailbox class-name failure) - JMH on JDK 17.0.17 and JDK 21.0.8 - Qoder review: No must-fix findings References: Refs apache#1668
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.
Motivation
JDKs affected by JDK-8180450 can lose multi-core scalability when the same concrete class is checked against alternating secondary supertypes. In Pekko Streams, this can happen in non-inlined user operator functions whose erased bridges cast the same elements to different interfaces.
The original issue analysis also suspected the fused
Connection.slot: Anyand genericgrab[T]path. Bytecode inspection and focused type-pollution-agent runs did not find pollution inGraphInterpreterorGraphStageLogic; the observed updates came from the user-function bridge casts. Changing the interpreter representation would therefore add hot-path risk without addressing the measured cause.Modification
Flow.maptest for the alternating-interface chain.Result
The benchmark reproduces the scalability loss on JDK 17.0.17 and verifies its removal in JDK 21.0.8. Scores are elements per microsecond with 12 JMH threads, 3 forks, and a six-map fused chain:
On JDK 17, alternating interfaces are about 50.6% slower than the stable-interface control. On JDK 21.0.8, the difference is within 0.4%.
The agent recorded roughly 12.1-12.4 million secondary-supertype cache changes per payload class at the benchmark
ToRight/ToLeftbridge casts. Narrowed runs targetingGraphInterpreterandGraphStageLogicreported no type-pollution sites, so this PR intentionally makes no core interpreter hot-path change.Tests
sbt "stream-tests / Test / testOnly org.apache.pekko.stream.scaladsl.FlowMapSpec"— passed, 3 testssbt "bench-jmh / Jmh / compile"— passedjavap -c— verifiedLeft/Rightbridgecheckcastinstructionssbt docs/paradox— passedsbt "+headerCheckAll" checkCodeStyle— passedsbt validatePullRequest— all Stream tests passed; docs validation hit the pre-existingjdocs.stream.IntegrationDocTestreference topekko.dispatch.UnboundedMailboxalready present onorigin/maingit diff --check— passedReferences
Refs #1668