Using Java Microbenchmark Harness (JMH) in a real world project
summary
Practical guide to adding JMH to a real project: use the JMH harness with Gradle + Shadow to build a fat JAR, run benchmarks via a custom Options API runner, and store results for CI; watch for default 10‑minute timeouts and set per‑benchmark to a day for long setups. Measured surprises: boxed Long keys create 1.3 GB/s garbage, case‑insensitive map caching runs 7–15× faster, batching DB writes gives ~5×, a pivot rewritten in SQL is 49× faster, and overall work build time cut from 3h to 45m.
AI-written summary · about
chapters (16)
- 0:00Introduction
- 1:08Benchmarking challenges
- 4:26JMH features
- 8:06Benchmarking workflow
- 11:04Setting up the harness
- 14:18Results and Jenkins
- 16:05JMH best practices
- 20:30Optimization stories
- 24:34Memory pressure
- 27:10Reflection optimization
- 29:05Object creation
- 30:48Array operations
- 32:46API design
- 34:26Database vs calculation
- 36:29N+1 query problem
- 37:41Conclusion and Q&A
