Bring the action: using GraalVM in production by Alina Yurenko

Learn how GraalVM native image optimizes Java apps with 3x lower memory usage & faster startup. Best practices for development, production deployment & monitoring.

Key takeaways
  • GraalVM native image can reduce application size by approximately 1/3 and memory usage by 3-5x compared to regular JVM applications

  • Development best practices:

    • Develop on JVM for fast feedback loops
    • Compile to native occasionally (e.g. daily/CI)
    • Use -O-b flag for faster builds during development
    • Use full optimizations (-O3) only for production builds
  • Three key optimization flags for production:

    • PGO (Profile Guided Optimization)
    • J1 GC policy
    • AMARK native
  • Making libraries work with native image:

    • Many modern frameworks like Spring Boot 3.x+ have built-in native support
    • Use GraalVM tracing agent to generate config for unsupported libraries
    • Leverage the GraalVM Reachability Metadata Repository
    • Manually write reflection/resource configs if needed
  • Performance characteristics:

    • Faster startup time compared to JVM
    • Lower average memory usage
    • Peak throughput can match JIT with proper optimization
    • More predictable memory usage patterns
  • Monitoring options:

    • Compatible with VisualVM
    • Integrated with Spring Actuator
    • JVM Stats monitoring support
    • Standard profiling tools work with native executables
  • Key limitations and considerations:

    • Longer build times compared to JVM
    • All reflection/dynamic features must be known at build time
    • Platform-specific builds required
    • Some libraries may need additional configuration