Skip to content

Instantly share code, notes, and snippets.

@headius
Last active February 13, 2025 14:38
Show Gist options
  • Save headius/1a5cfbc91ed8bacd194f1c592a90c275 to your computer and use it in GitHub Desktop.
Save headius/1a5cfbc91ed8bacd194f1c592a90c275 to your computer and use it in GitHub Desktop.
Experimenting with JDK24 AOT caching and JRuby

Baseline startup

Base startup numbers with and without CDS (--nocache disables CDS), with and without --dev (simpler JVM JIT and no JRuby JIT)

[] jruby $ time jruby --nocache -e 1      
jruby --nocache -e 1  2.48s user 0.17s system 148% cpu 1.777 total
[] jruby $ time jruby --nocache -e 1
jruby --nocache -e 1  2.37s user 0.13s system 185% cpu 1.340 total
[] jruby $ time jruby --nocache -e 1
jruby --nocache -e 1  2.38s user 0.12s system 188% cpu 1.330 total
[] jruby $ time jruby --nocache -e 1
jruby --nocache -e 1  2.41s user 0.13s system 188% cpu 1.349 total

[] jruby $ time jruby -e 1          
jruby -e 1  1.82s user 0.14s system 171% cpu 1.142 total
[] jruby $ time jruby -e 1
jruby -e 1  1.93s user 0.11s system 198% cpu 1.029 total
[] jruby $ time jruby -e 1
jruby -e 1  1.77s user 0.10s system 196% cpu 0.953 total

[] jruby $ time jruby --nocache --dev -e 1 
jruby --nocache --dev -e 1  1.17s user 0.11s system 103% cpu 1.230 total
[] jruby $ time jruby --nocache --dev -e 1
jruby --nocache --dev -e 1  1.17s user 0.08s system 131% cpu 0.948 total
[] jruby $ time jruby --nocache --dev -e 1
jruby --nocache --dev -e 1  1.17s user 0.09s system 126% cpu 0.989 total
[] jruby $ time jruby --nocache --dev -e 1
jruby --nocache --dev -e 1  1.17s user 0.09s system 131% cpu 0.958 total

[] jruby $ time jruby --dev -e 1   
jruby --dev -e 1  0.89s user 0.08s system 128% cpu 0.757 total
[] jruby $ time jruby --dev -e 1
jruby --dev -e 1  0.87s user 0.08s system 127% cpu 0.745 total
[] jruby $ time jruby --dev -e 1
jruby --dev -e 1  0.87s user 0.07s system 127% cpu 0.739 total
[] jruby $ time jruby --dev -e 1

Recording for AOT cache

[] jruby $ jruby --nocache -J-XX:AOTMode=record -J-XX:AOTConfiguration=lib/jruby.aotconf -e '100.times { org.jruby.Ruby.newInstance.tearDown }'
[] jruby $ jruby --nocache -J-XX:AOTMode=create -J-XX:AOTConfiguration=lib/jruby.aotconf -J-XX:AOTCache=lib/jruby.aot -e '100.times { org.jruby.Ruby.newInstance.tearDown }'
[2.525s][warning][cds] java.lang.ClassNotFoundException: DashE
[2.525s][warning][cds] Preload Warning: Cannot find DashE
[2.820s][warning][cds] Skipping jdk/internal/event/Event: JFR event class
AOTCache creation is complete: lib/jruby.aot

AOT cache, no CDS

[] jruby $ time jruby --nocache -J-XX:AOTCache=lib/jruby.aot -e 1
jruby --nocache -J-XX:AOTCache=lib/jruby.aot -e 1  1.73s user 0.13s system 196% cpu 0.947 total
[] jruby $ time jruby --nocache -J-XX:AOTCache=lib/jruby.aot -e 1
jruby --nocache -J-XX:AOTCache=lib/jruby.aot -e 1  1.76s user 0.13s system 198% cpu 0.952 total
[] jruby $ time jruby --nocache -J-XX:AOTCache=lib/jruby.aot -e 1
jruby --nocache -J-XX:AOTCache=lib/jruby.aot -e 1  1.79s user 0.12s system 204% cpu 0.935 total
[] jruby $ time jruby --nocache -J-XX:AOTCache=lib/jruby.aot -e 1
jruby --nocache -J-XX:AOTCache=lib/jruby.aot -e 1  1.73s user 0.13s system 199% cpu 0.932 total

Longer training run

[] jruby $ jruby --nocache -J-XX:AOTMode=record -J-XX:AOTConfiguration=lib/jruby.aotconf -e '1000.times { r = org.jruby.Ruby.newInstance; r.evalScriptlet(%[require "rubygems"]); r.tearDown }'
[] jruby $ jruby --nocache -J-XX:AOTMode=create -J-XX:AOTConfiguration=lib/jruby.aotconf -J-XX:AOTCache=lib/jruby.aot -e '100.times { org.jruby.Ruby.newInstance.tearDown }'              
[2.506s][warning][cds] java.lang.ClassNotFoundException: DashE
[2.506s][warning][cds] Preload Warning: Cannot find DashE
[2.809s][warning][cds] Skipping jdk/internal/event/Event: JFR event class
AOTCache creation is complete: lib/jruby.aot

AOT cache, no CDS

[] jruby $ time jruby --nocache -J-XX:AOTCache=lib/jruby.aot -e 1                                                                                                                              
jruby --nocache -J-XX:AOTCache=lib/jruby.aot -e 1  2.73s user 0.17s system 277% cpu 1.047 total
[] jruby $ time jruby --nocache -J-XX:AOTCache=lib/jruby.aot -e 1
jruby --nocache -J-XX:AOTCache=lib/jruby.aot -e 1  2.87s user 0.16s system 286% cpu 1.058 total
[] jruby $ time jruby --nocache -J-XX:AOTCache=lib/jruby.aot -e 1
jruby --nocache -J-XX:AOTCache=lib/jruby.aot -e 1  2.82s user 0.14s system 279% cpu 1.057 total
[] jruby $ time jruby --nocache -J-XX:AOTCache=lib/jruby.aot -e 1
jruby --nocache -J-XX:AOTCache=lib/jruby.aot -e 1  2.85s user 0.16s system 279% cpu 1.075 total
[] jruby $ time jruby --nocache -J-XX:AOTCache=lib/jruby.aot -e 1
jruby --nocache -J-XX:AOTCache=lib/jruby.aot -e 1  3.12s user 0.18s system 245% cpu 1.344 total

Add in --dev

[] jruby $ time jruby --nocache -J-XX:AOTCache=lib/jruby.aot --dev -e 1
jruby --nocache -J-XX:AOTCache=lib/jruby.aot --dev -e 1  0.85s user 0.09s system 107% cpu 0.869 total
[] jruby $ time jruby --nocache -J-XX:AOTCache=lib/jruby.aot --dev -e 1
jruby --nocache -J-XX:AOTCache=lib/jruby.aot --dev -e 1  0.92s user 0.09s system 120% cpu 0.835 total
[] jruby $ time jruby --nocache -J-XX:AOTCache=lib/jruby.aot --dev -e 1
jruby --nocache -J-XX:AOTCache=lib/jruby.aot --dev -e 1  0.84s user 0.08s system 126% cpu 0.732 total
[] jruby $ time jruby --nocache -J-XX:AOTCache=lib/jruby.aot --dev -e 1
jruby --nocache -J-XX:AOTCache=lib/jruby.aot --dev -e 1  0.85s user 0.07s system 127% cpu 0.722 total
[] jruby $ time jruby --nocache -J-XX:AOTCache=lib/jruby.aot --dev -e 1
jruby --nocache -J-XX:AOTCache=lib/jruby.aot --dev -e 1  0.85s user 0.07s system 127% cpu 0.722 total

Try training it for --dev

[] jruby $ jruby --nocache -J-XX:AOTMode=record -J-XX:AOTConfiguration=lib/jruby.aotconf --dev -e '1000.times { r = org.jruby.Ruby.newInstance; r.evalScriptlet(%[require "rubygems"]); r.tearDown; print ?. }'
........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
[] jruby $ jruby --nocache -J-XX:AOTMode=create -J-XX:AOTConfiguration=lib/jruby.aotconf -J-XX:AOTCache=lib/jruby.aot
[2.846s][warning][cds] Skipping jdk/internal/event/Event: JFR event class
AOTCache creation is complete: lib/jruby.aot
[] jruby $ time jruby --nocache -J-XX:AOTCache=lib/jruby.aot --dev -e 1                                                                                                                                        
jruby --nocache -J-XX:AOTCache=lib/jruby.aot --dev -e 1  0.99s user 0.14s system 151% cpu 0.749 total
[] jruby $ time jruby --nocache -J-XX:AOTCache=lib/jruby.aot --dev -e 1
jruby --nocache -J-XX:AOTCache=lib/jruby.aot --dev -e 1  0.93s user 0.11s system 145% cpu 0.717 total
[] jruby $ time jruby --nocache -J-XX:AOTCache=lib/jruby.aot --dev -e 1
jruby --nocache -J-XX:AOTCache=lib/jruby.aot --dev -e 1  0.88s user 0.08s system 134% cpu 0.712 total
[] jruby $ time jruby --nocache -J-XX:AOTCache=lib/jruby.aot --dev -e 1
jruby --nocache -J-XX:AOTCache=lib/jruby.aot --dev -e 1  0.89s user 0.08s system 134% cpu 0.723 total
[] jruby $ time jruby --nocache -J-XX:AOTCache=lib/jruby.aot --dev -e 1
jruby --nocache -J-XX:AOTCache=lib/jruby.aot --dev -e 1  0.87s user 0.08s system 132% cpu 0.717 total
[] jruby $ time jruby --nocache -J-XX:AOTCache=lib/jruby.aot --dev -e 1
jruby --nocache -J-XX:AOTCache=lib/jruby.aot --dev -e 1  0.87s user 0.07s system 128% cpu 0.732 total
[] jruby $ time jruby --nocache -J-XX:AOTCache=lib/jruby.aot --dev -e 1
jruby --nocache -J-XX:AOTCache=lib/jruby.aot --dev -e 1  0.88s user 0.07s system 128% cpu 0.744 total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment