Investigation finds G1GC card-marking barrier makes Arrays.fill 265x slower than ParallelGC
A JMH benchmark filling two reference arrays showed drastically different results depending on garbage collector: about 0.5ms on ParallelGC versus 139ms on G1GC, despite no garbage collection occurring during the measured operations. The author traces this gap through JIT compilation and JVM flags down to a specific machine instruction responsible for the slowdown.
GoKawiil's interpretation of the reporting above, not reported fact.
This shows that GC choice can silently affect hot-path performance even when no collection is happening, through mechanisms like write barriers used for tracking cross-region references. Developers benchmarking or tuning JVM applications need to be aware that switching collectors can introduce order-of-magnitude regressions in seemingly unrelated code like array fills.
- G1GC's write barrier overhead can make simple array-fill operations vastly slower than on ParallelGC, even with zero GC activity.
- The root cause traces to a specific machine instruction tied to G1's card-marking mechanism for tracking inter-region object references.
- JVM flag tuning and diagnostic tools were needed to pinpoint the exact source of the 265x performance gap.
Optimizing Java (O'Reilly) by Benjamin Evans — If digging into G1 vs ParallelGC write barriers and JIT behavior excites you, this O'Reilly book covers JVM internals, garbage collection tuning and benchmarking practice in depth. It's a great companion for anyone writing JMH benchmarks and puzzling over surprising performance numbers.
See Optimizing Java (O'Reilly) by Benjamin Evans on Amazon → Affiliate link — we may earn a commission on purchases, at no extra cost to you. Product picked by AI based on this article; it is not a tested recommendation.Source: krzysztofslusarski.github.io, 2026-09-01
Published there as: “Why is Arrays.fill 265 times slower on G1GC?”
Read the original report → The summary and analysis above are GoKawiil's own, written from reporting by the source above. Facts and quotes belong to the original publisher.