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>:
I ran out of memory trying to build a PGO instrumented native image:
[3/8] Building universe... (10.1s @ 4.38GB)
[4/8] Parsing methods... [**] (4.8s @ 4.71GB)
[5/8] Inlining methods... [**] (0.5s @ 4.80GB)
[6/8] Compiling methods... [****************] (259.4s @ 7.40GB)
GC warning: 170.0s spent in 1126 GCs during the last stage, taking up 65.53% of the time.
Please ensure more than 9.35GB of memory is available for Native Image
to reduce GC overhead and improve image build time.
Terminating due to java.lang.OutOfMemoryError: Java heap space
The Native Image build process ran out of memory.
Please make sure your build system has more memory available.
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