When Greed Is Good: Understanding Java Stream Performance
summary
Explains how Java streams actually execute by showing JMH benchmarks, JITWatch assembly, and flame graphs that reveal surprising costs: adding a limit produces a 50% slowdown with limit in one microbenchmark, parallelizing a suitable workload gives 14x speedup on 14 cores, and cancellation checks dominate runtime when pipelines short-circuit. Demonstrates the Java 25 gatherer API with a zip-with-index example, contrasts greedy vs non-greedy gatherers, and recommends profiling hot pipelines before rewriting to loops.
AI-written summary · about
chapters (10)
- 0:00Introduction and speaker background
- 4:53Why use Java streams
- 10:10Debugging stream pipeline internals
- 14:05JIT inlining in stream operations
- 16:32Impact of adding limit to streams
- 23:18Parallel streams performance pitfalls
- 29:03Introducing Java 25 gatherers
- 34:46Greedy vs picky gatherers
- 40:11Performance conclusions and recommendations
- 43:01Q&A session
related talks
47mStreams – Below the Surface
01h 00mLet’s Get to the Rapids: Java 8 Stream Performance
57mMaximizing the Performance of Java 8 Streams
44mI didn't know you could do that with Java Streams!
44mThinking in Streams
49mJava Streams: Beyond The Basics
51mIf Streams Are So Great, Let’s Use Them Everywhere... Right??
46mMake Your CPU Cores Sweat with Parallel Streams
