Profile Guided Optimization
After we restored tracing capability in Traces In Native Image Via Datadog
Let's take a look at Profile Guided Optimization (PGO).
This technique allows you to generate a profile at runtime of optimizations that the JVM applies and bring them to build time for your next native image build.
You will need GraalVM Enterprise Edition for PGO builds.
Setup
The first thing we need is to build a native image capable of collecting runtime data.
As in previous articles, we use the native image Maven plugin to pass the argument <arg>--pgo-instrument</arg>
:
Build with
Check the logs for Active PGO instrumentation:

Notably,
I ran out of memory trying to build a PGO instrumented native image:
The process took longer than the usual 8 minutes I was getting with -Ob quick build mode:

The binary generated was larger:

Collect
During this phase, you would ideally use workloads similar to your production environment.
I will just send hundreds of queries through Postman's Collection runs.
This generates a profile default.iprof
that we will use in the next step:

Pass the profile to Native Image
Pass the --pgo
argument to the native image build tool:
Rebuild:
Check for Active PGO:
