Reputation: 332
Is there any way to speed up the startup time of Groovy? (Except using the some kind of separate running Groovy process, as has been suggested).
I don't care much about execution times, but the slow startup is making it impossible to develop in Groovy for me.
A simple comparison between starting and running an empty script, using Groovy and Ruby on my machine:
$ time groovy -e ""
real 0m5.678s
user 0m6.468s
sys 0m0.456s
$ time ruby -e ""
real 0m0.023s
user 0m0.020s
sys 0m0.004s
I am running Ubuntu 11.10 using the standard packages in the repositories.
$ groovy -v
Groovy Version: 1.7.10 JVM: 1.6.0_23
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=11.10
DISTRIB_CODENAME=oneiric
DISTRIB_DESCRIPTION="Ubuntu 11.10"
$ java -version
java version "1.6.0_23"
OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10.1)
OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)
Upvotes: 4
Views: 1708
Reputation: 41168
The JVM itself has a lot of startup overhead and is best for long-running processes.
Even though you said "Except using the some kind of separate running Groovy process, as I has been suggested" you may want to take a look at Nailgun.
6 seconds seems excessive. Here are the results I had with the same test:
$ time groovy -e ""
real 0m0.588s
user 0m0.484s
sys 0m0.056s
$ time groovy -e ""
real 0m0.856s
user 0m1.114s
sys 0m0.125s
$ groovy -version
Groovy Version: 1.8.5 JVM: 1.6.0_29 Vendor: Apple Inc. OS: Mac OS X
$ java -version
java version "1.6.0_29"
Java(TM) SE Runtime Environment (build 1.6.0_29-b11-402-11M3527)
Java HotSpot(TM) 64-Bit Server VM (build 20.4-b02-402, mixed mode)
Upvotes: 1
Reputation: 66069
This is a combination of JVM overhead, plus groovy's own startup time. Adding the -noverify
flag to the JVM options turns off bytecode verification, which makes a noticeable difference. Set the JAVA_OPTS
environment variable to -noverify
to get groovy to use it.
There's also project to run a server process in the background to get around this: http://kobo.github.com/groovyserv/
Upvotes: 6