I'm using JRuby to run some Ruby scripts from Java and collect the results. Everything works fine, but performance is unacceptably slow - while executing script.rb
from terminal takes about 0.3 seconds, executing it via JRuby from Java takes over 10 seconds. The code I'm using is:
ScriptingContainer jruby = new ScriptingContainer(LocalContextScope.THREADSAFE);
String script = readScript("script.rb");
Object receiver = jruby.runScriptlet(script); // takes ~10 seconds
Map<String, String> executionResult = (Map<String, String>) jruby.callMethod(receiver, ...);
The bottleneck is the runScriptlet()
method, which takes 8-10 seconds on an otherwise normally performant Linux machine. I'm using JRuby 9.1.6.0 with Java 8 (openjdk 1.8).
Am I doing something wrong - perhaps missing some essential settings - or is this just how slow JRuby really is? Has anybody else encountered this?