On Thu, Feb 17, 2011 at 1:31 PM, Per Bothner <[email protected]> wrote:
> It doesn't seem that bad for Kawa:
>
> $ time java -Xbootclasspath/a:kawa-1.11.jar kawa.repl \
>  -e '(define (plus a b) (+ a b))' \
>  -e '(format "Sum: ~d~%" (plus 2 3))'
> Sum: 5
>
> real    0m0.207s
> user    0m0.186s
> sys     0m0.037s
>
> This loads Kawa, compiles and loads a function named plus, and then
> compiles and loads an expression that invokes that function followed
> by printing the result (a la printf).  In both case we do a full
> compile-to-bytecode, including analysis and optimization passes.
> So a fair number of classes get loaded and used.

I would expect Ruby/JRuby startup to be worse than Kawa, since there's
a much larger set of core libraries to be initialized. But JRuby's
also "not bad" on a 2-year-old MBP:

~/projects/jruby-ossl ➔ time jruby -e "'Sum %d' % (2 + 3)"

real    0m0.667s
user    0m0.589s
sys     0m0.090s

A runhprof is probably not super accurate for measuring startup, but
here's the top ten items:

   1  2.74%  2.74%      12 323242 java.util.jar.JarFile.getInputStream
   2  2.34%  5.08%      23 327645 java.util.zip.ZipFile$ZipFileInputStream.close
   3  2.12%  7.19%     389 327376 java.math.BigInteger.montReduce
   4  1.89%  9.09%       1 319193 org.jruby.parser.DefaultRubyParser.<clinit>
   5  1.77% 10.85%     314 323316 java.util.LinkedList.indexOf
   6  1.47% 12.32%     311 327372 java.math.BigInteger.squareToLen
   7  1.29% 13.62%   23277 323315 java.lang.String.equals
   8  1.02% 14.64%       1 315060 org.jruby.Ruby.initCore
   9  0.85% 15.48%    4142 324999 java.lang.Character.toLowerCase
  10  0.75% 16.23%      33 322956 sun.net.www.ParseUtil.decode

It's fair to say much of the startup is simply due to the size of
JRuby: loading the jar contents, preparing parser, booting core
classes...

Now the unfortunate thing is that a good portion of this appear to go
away with a hot JVM. Here's numbers using Nailgun, which keeps a JVM
running and launches commands there:

~/projects/jruby-ossl ➔ time jruby --ng -e "'Sum %d' % (2 + 3)"

real    0m1.483s
user    0m0.001s
sys     0m0.003s

~/projects/jruby-ossl ➔ time jruby --ng -e "'Sum %d' % (2 + 3)"

real    0m0.093s
user    0m0.001s
sys     0m0.003s

This is comfortably within the speed necessary for command-line tools.

We have also experimented with making some of the boot-time stuff
lazy, but found that for anything nontrivial almost all core classes
actually do need to be initialized, and for typical Ruby apps and
commands the startup time ends up being the locating, parsing, and
interpreting of source files on disk, the latter two of which warm up
very well but perform terribly when cold. So simply doing less init or
doing init lazily doesn't address the fact that the JVM just isn't
fast for its first few seconds of life.

- Charlie

- Charlie

-- 
You received this message because you are subscribed to the Google Groups "JVM 
Languages" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/jvm-languages?hl=en.

Reply via email to