Skip to content

Latest commit

 

History

History

list-files

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Create a Native Executable and Apply Profile-Guided Optimization

This demo shows how to create a native executable with GraalVM Native Image and apply Profile-Guided Optimization (PGO) for more performance gains. It uses the Java application that counts files and their sizes in a specified directory.

Run the Demo

  1. Compile the application:

    javac ListDir.java
  2. Generate a native executable from the class file:

    native-image ListDir

    The executable file listdir is created in the directory.

  3. Run the application by passing it a directory that actually contains some files, for example .. (to count files in the parent of the current directory, containing all the demos in this repository). Check the time spent with the time utility.

    • On HotSpot:
      time java ListDir ..
    • From a native executable:
      time ./listdir ..

Enable PGO

For more performance gains, you can can apply Profile-Guided Optimization (PGO). (Not available with GraalVM Community Edition.) With PGO you can collect the profiling data, and then feed it to the native-image tool, which will use this information to further optimize the performance of the resulting executable.

  1. Build an instrumented image from the ListDir class and run it to collect profiles, specifying a different name for the native executable, for example listdir-instrumented:

    native-image --pgo-instrument ListDir -o listdir-instrumented
    ./listdir-instrumented ..

    Profiles collected from this run are now stored in the default.iprof file.

  2. Use the profiles to build an optimized native executable, giving it a different name than in the previous runs:

    native-image --pgo ListDir -o listdir-optimized
  3. Run that optimized executable:

    time ./listdir-optimized ..

Find more examples at the website: