Skip to content

Commit

Permalink
Improve configuration of native image compilation
Browse files Browse the repository at this point in the history
- Solve msgpack issue with `--initialize-at-run-time`.
- Use quick build mode for 40% faster compilation and 20% smaller executable
  (tested on Linux amd64). If necessary, this can be disabled for release builds.
  Note that with the move from GraalVM CE 22 to Oracle GraalVM 23, native image
  compilation time has doubled and binary size has increased to 120 MiB on Linux amd64.
- Use Intel Skylake (2015) CPU features for amd64 executables.
- Remove options that are commented out.
  • Loading branch information
translatenix committed Apr 25, 2024
1 parent a7c7e51 commit f7b28a0
Showing 1 changed file with 10 additions and 28 deletions.
38 changes: 10 additions & 28 deletions pkl-cli/pkl-cli.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -160,47 +160,29 @@ fun Exec.configureExecutable(
// that the "initialize everything at build time" *CLI* option is likely here to stay
"--initialize-at-build-time="
// needed for messagepack-java (see https://github.com/msgpack/msgpack-java/issues/600)
,"--add-opens=java.base/java.nio=ALL-UNNAMED"
,"--add-opens=java.base/sun.nio.ch=ALL-UNNAMED"
,"--initialize-at-run-time=org.msgpack.core.buffer.DirectBufferAccess"
,"--no-fallback"
,"-H:IncludeResources=org/pkl/core/stdlib/.*\\.pkl"
,"-H:IncludeResources=org/jline/utils/.*"
,"-H:IncludeResources=org/pkl/certs/PklCARoots.pem"
//,"-H:IncludeResources=org/pkl/core/Release.properties"
,"-H:IncludeResourceBundles=org.pkl.core.errorMessages"
,"--macro:truffle"
,"-H:Class=org.pkl.cli.Main"
,"-H:Name=${outputFile.get().asFile.name}"
//,"--native-image-info"
//,"-Dpolyglot.image-build-time.PreinitializeContexts=pkl"
// the actual limit (currently) used by native-image is this number + 1400 (idea is to compensate for Truffle's own nodes)
,"-H:MaxRuntimeCompileMethods=1800"
,"-H:+EnforceMaxRuntimeCompileMethods"
,"--enable-url-protocols=http,https"
//,"--install-exit-handlers"
,"-H:+ReportExceptionStackTraces"
,"-H:-ParseRuntimeOptions" // disable automatic support for JVM CLI options (puts our main class in full control of argument parsing)
//,"-H:+PrintAnalysisCallTree"
//,"-H:PrintAnalysisCallTreeType=CSV"
//,"-H:+PrintImageObjectTree"
//,"--features=org.pkl.cli.svm.InitFeature"
//,"-H:Dump=:2"
//,"-H:MethodFilter=ModuleCache.getOrLoad*,VmLanguage.loadModule"
//,"-g"
//,"-verbose"
//,"--debug-attach"
//,"-H:+AllowVMInspection"
//,"-H:+PrintHeapHistogram"
//,"-H:+ReportDeletedElementsAtRuntime"
//,"-H:+PrintMethodHistogram"
//,"-H:+PrintRuntimeCompileMethods"
//,"-H:NumberOfThreads=1"
//,"-J-Dtruffle.TruffleRuntime=com.oracle.truffle.api.impl.DefaultTruffleRuntime"
//,"-J-Dcom.oracle.truffle.aot=true"
//,"-J:-ea"
//,"-J:-esa"
// for use with https://www.graalvm.org/docs/tools/dashboard/
//,"-H:DashboardDump=dashboard.dump", "-H:+DashboardAll"
// disable automatic support for JVM CLI options (puts our main class in full control of argument parsing)
,"-H:-ParseRuntimeOptions"
// quick build mode: 40% faster compilation, 20% smaller (but presumably also slower) executable
,"-Ob"
// Use Intel Skylake (2015) CPU features, which should also be supported by AMD ZEN (2017) CPUs.
// Tested on ZEN 2.
// Feature list: CX8, CMOV, FXSR, MMX, SSE, SSE2, SSE3, SSSE3, SSE4_1, SSE4_2, POPCNT,
// LZCNT, AVX, AVX2, AES, CLMUL, BMI1, BMI2, FMA, AMD_3DNOW_PREFETCH, ADX, FLUSHOPT
, if (buildInfo.arch == "amd64") "-march=skylake" else ""
// native-image rejects non-existing class path entries -> filter
,"--class-path"
,((sourceSets.main.get().output + configurations.runtimeClasspath.get())
Expand Down

0 comments on commit f7b28a0

Please sign in to comment.