Java Performance Puzzlers by Douglas Hawkins
Why Stack Overflow recommends it
Stack Overflow users link it when explaining JIT warmup, microbenchmarking pitfalls, and why intuition about Java performance often fails.
Recommended by 2 people across 2 different months, 2021 to 2023.
What it is
A Devoxx conference talk by Douglas Hawkins, a VM engineer at Azul Systems, walking through surprising and unintuitive Java performance problems. It uses puzzles to explain how JVM optimizations like JIT compilation and CPU behavior such as caches make performance hard to reason about.
What people said
Recommends daniu · 2021-05 · Stack Overflow · on “inner Functions vs outer (static) methods”
You do need to use proper tools to measure performance; here's a discussion [LINK] . This video [this video] has a short introduction to what JMH does and should give an idea as to why.
Recommends rzwitserloot · 2021-12 · Stack Overflow · on “Runtime of Sorting-Algorithms gets faster (in Java)”
I think, the machine learns, and it becomes faster Yup. Look up Just-in-time compilation [LINK] and while you're at it, spend a few weeks becoming a rocket scientist so that you can fully understand how CPU caches [LINK] work. Or, if you don't want to spend the next 10 weeks studying but you do want a much better idea of how any of this works, read the rest of this answer, then go look at this talk by Douglas Hawkins about JVM performance puzzlers [this video] . I bet after watching those 40 minutes you will feel fully enlightened about this conundrum. Two things are going on here (JIT warmup effect, and cachepage effect), possibly more: The JIT is 'warming up': The way java works, is that it run
Cites rzwitserloot · 2021-06 · Stack Overflow · on “how fragile is escape analysis in Hotspot in simple cases such as iterator in for-each loop”
Your approach does not work. The correct approach is this: Unless you are a performance expert (which is hard to become), do not make assumptions about what kind of code performs well vs. performs poorly, and maintain skepticism when analysing profiler reports. This is not particularly useful advice (it boils down to: A profiler report may be lying to you!), but it is what it is. Effectively, either be a performance expert, or accept that there's not much you can do about it. Sucks, but, don't shoot the messenger. Write idiomatic java code. It is easiest to maintain and most likely to get optimized by hotspot. Reduction of algorithmic complexity is useful and should always be the first thing
Cites Philzen · 2023-07 · Stack Overflow · on “Maximum size of a method in java?”
@MeBigFatGuy See [this video] – **Important addition**: We're talking about the bytecode, not size of the java code that you're writing.