Phase 08 — Performance Engineering

Why This Phase Matters

An Apache committer's most common review comment isn't about style — it's "do you have numbers to back this up?"

Performance claims without measurements are opinions. JMH-backed numbers are facts you can put in a commit message, a PR description, or an ASF mailing list discussion.

This phase gives you the toolkit to measure, interpret, and defend performance claims for JVM code at the level Apache reviewers expect.


Labs

#TitleCore skillKey class
01JMH MicrobenchmarksWrite and interpret JMH benchmarksStringConcatBenchmark, CollectionLookupBenchmark
02GC & Allocation ProfilingMeasure autoboxing and allocation overheadBoxingBenchmark, StreamVsLoopBenchmark
03Lock Contention AnalysisCompare synchronization primitives under thread contentionContentionBenchmark, ContentionCorrectnessTest

Core Concepts

ConceptWhat it meansWhy it matters
Dead code eliminationJIT removes code whose result is never used — defeats naive benchmarksJMH uses Blackhole to prevent this
Constant foldingJIT computes 2 + 2 at compile time — benchmark measures nothingJMH uses @State fields to prevent this
JIT warm-upFirst 10k–50k iterations are interpreted; they are not representativeJMH @Warmup discards early iterations
Coordinated omissionRecording only when you're ready to record hides high-latency tailsUse JMH SampleTime mode for latency distributions
False sharingTwo fields on the same cache line — writing one invalidates the otherUse @Contended / padding for high-frequency shared fields

What You'll Build

  • Lab 01: Three JMH benchmarks that expose common Java anti-patterns (+= in loops, O(n) contains, double map lookups). Reproducible numbers you can quote in code reviews.
  • Lab 02: JMH benchmarks measuring autoboxing overhead and stream vs imperative loop cost. Correctness tests verifying that the "fast" versions produce identical results.
  • Lab 03: Four Counter implementations (synchronized, ReentrantLock, AtomicLong, LongAdder) benchmarked under 4-thread contention. Correctness test confirms thread safety.

Prerequisites

  • Phase 07 Lab 01 (Raft) — concurrency concepts
  • Java 11+, Maven 3.8+

Interview Relevance

"Why is synchronized sometimes faster than AtomicLong at low thread counts?"
"What's wrong with using System.currentTimeMillis() for benchmarking?"
"How would you measure the overhead of autoboxing in a hot path?"

All three have direct answers from this phase's lab output.