Java / GraalVM Interview questions
Why should you use Profile-Guided Optimization (PGO) with Native Image?
Because a native image is compiled entirely ahead of time with no live runtime profiling feedback loop like a JIT gets, the compiler has to make static guesses about which branches are hot and which methods are worth inlining aggressively - guesses that are often wrong for real-world traffic patterns.
PGO closes that gap in two passes: first you build an "instrumented" image that records real execution profiles (branch frequencies, call-site targets) while running representative workloads, then you rebuild the final image using --pgo=default.iprof, feeding those recorded profiles back into the AOT compiler so it makes the same kind of informed inlining and branch-layout decisions a warmed-up JIT would.
native-image --pgo-instrument -jar app.jar ./app # run representative workload, produces default.iprof native-image --pgo=default.iprof -jar app.jar
The result is peak throughput noticeably closer to a fully warmed-up JVM, without giving up Native Image's fast-startup, low-memory profile - though it does require a realistic workload during the profiling run, since profiles from an unrepresentative run can mislead the final compile.
More Related questions...