Skip to content

Commit f1c79c4

Browse files
committed
Add steps for PGO-optimized GraalVM native image build
1 parent e567276 commit f1c79c4

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

jsoniter-scala-examples/README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Expected output:
102102
```sh
103103
sudo apt install linux-tools-common linux-tools-generic gcc zlib1g-dev
104104
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
106106
ls -l ./example01_graalvm.bin
107107
perf stat -r 100 ./example01_graalvm.bin > /dev/null
108108
```
@@ -212,6 +212,32 @@ user 1m29.199s
212212
sys 0m5.151s
213213
```
214214

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+
215241
### Build Scala Native image, print its size, and measure its running time
216242

217243
```sh

0 commit comments

Comments
 (0)