@@ -102,7 +102,7 @@ Expected output:
102
102
``` sh
103
103
sudo apt install linux-tools-common linux-tools-generic gcc zlib1g-dev
104
104
sudo sysctl kernel.perf_event_paranoid=1
105
- scala-cli --power package --graalvm-jvm-id graalvm-oracle:23 --native-image example01.sc --force -o example01_graalvm.bin -- --no-fallback -O3
105
+ scala-cli --power package --graalvm-jvm-id graalvm-oracle:23 --native-image example01.sc --force -o example01_graalvm.bin -- --no-fallback -march=native
106
106
ls -l ./example01_graalvm.bin
107
107
perf stat -r 100 ./example01_graalvm.bin > /dev/null
108
108
```
@@ -212,6 +212,32 @@ user 1m29.199s
212
212
sys 0m5.151s
213
213
```
214
214
215
+ You can use profile guided optimization (PGO) to improve performance of Oracle GraalVM native image, for that you need:
216
+ - build an instrumented GraalVM native image with ` --pgo-instrument ` option added:
217
+ ``` sh
218
+ scala-cli --power package --graalvm-jvm-id graalvm-oracle:23 --native-image example02.sc --force -o example02_graalvm_instrumented.bin -- --no-fallback --gc=epsilon -O3 --pgo-instrument
219
+ ls -l ./example02_graalvm_instrumented.bin
220
+ ```
221
+ - run the instrumented image and collect the profile data:
222
+ ``` sh
223
+ time ./example02_graalvm_instrumented.bin < 2023_06_430_65B0_in_network_rates.json 2> /dev/null
224
+ ```
225
+ - build a PGO-optimized GraalVM native image with ` --pgo=default.iprof ` option added:
226
+ ``` sh
227
+ scala-cli --power package --graalvm-jvm-id graalvm-oracle:23 --native-image example02.sc --force -o example02_graalvm_optimized.bin -- --no-fallback --gc=epsilon -O3 --pgo=default.iprof
228
+ ls -l ./example02_graalvm_optimized.bin
229
+ ```
230
+ - run the PGO-optimized image:
231
+ ``` sh
232
+ time ./example02_graalvm_optimized.bin < 2023_06_430_65B0_in_network_rates.json 2> /dev/null
233
+ ```
234
+ Expected output:
235
+ ``` text
236
+ real 1m20.185s
237
+ user 1m15.976s
238
+ sys 0m4.207s
239
+ ```
240
+
215
241
### Build Scala Native image, print its size, and measure its running time
216
242
217
243
``` sh
0 commit comments