Skip to content

Instantly share code, notes, and snippets.

@enebo
Created January 28, 2020 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enebo/a9ec1111b3228f39c1211d54cb5f44e6 to your computer and use it in GitHub Desktop.
Save enebo/a9ec1111b3228f39c1211d54cb5f44e6 to your computer and use it in GitHub Desktop.

Note: I ran each of the timed runs multiple times but picked the lowest number of each

Only first rails spawn -X+C

Generate ~/.ir fresh:

time echo exit | CLASSPATH=/home/enebo/.ir JRUBY_OPTS="-Xcompile.cache.classes=true -J-XX:+UseParallelGC" jruby -X+C -S rails c

Notice it is not in JRUBY_OPTS so second spawn of Rails will not compile. This will only generate 134 files in ~/.ir

Now run with cache on:

% time echo exit | CLASSPATH=/home/enebo/.ir JRUBY_OPTS="-Xcompile.cache.classes=true --dev -J-XX:+UseParallelGC" jruby -S rails c

real	0m12.186s
user	0m15.310s
sys	0m1.235s

And off:

time echo exit | CLASSPATH=/home/enebo/.ir JRUBY_OPTS="-Xcompile.cache.classes=false --dev -J-XX:+UseParallelGC" jruby -S rails c

real	0m14.435s
user	0m17.343s
sys	0m1.228s

Cache classes in both rails processes

Generate ~/.ir fresh:

time echo exit | CLASSPATH=/home/enebo/.ir JRUBY_OPTS="-Xcompile.cache.classes=true -X+C -J-XX:+UseParallelGC" jruby -S rails c

With cache on:

% time echo exit | CLASSPATH=/home/enebo/.ir JRUBY_OPTS="-Xcompile.cache.classes=true --dev -J-XX:+UseParallelGC" jruby -S rails c

real	0m14.322s
user	0m17.854s
sys	0m1.250s

With cache off:

time echo exit | CLASSPATH=/home/enebo/.ir JRUBY_OPTS="-Xcompile.cache.classes=false --dev -J-XX:+UseParallelGC" jruby -S rails c

real	0m14.409s
user	0m17.330s
sys	0m1.125s

We can see cache off should be the same speed and it is pretty much but with cache on only loading those first 134 files seems like a much larger win. To me, this implies two possible outcomes:

  1. loading everything as bytecode is slower than parse + interp
  2. some jitting is helping speed up startup because it warms quicker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment