开发者

Improving Scala script startup time -- client mode?

I'd like to get short Scala scripts running as fast as python scripts do, particularly in terms of script startup time.

Can anyone recommend开发者_JAVA技巧 some ways of doing this, that doesn't involve compiling with GCJ, for instance?

One way I can think of is to run the script using the JVM's client mode, but I can't seem to get this working. An example (known-good) shebang for this would be great.

UPDATE: I'm aware of the other questions, but don't think any workable answers have been found so far, as I'm looking for solutions that work on STANDARD installs, without additional requirements. This is what I was trying to get at with "doesn't involve compiling with GCJ, for instance".

It seems that -client mode is designed for this express purpose, but it's just awkward to activate from scala scripts for some reason.


As many other questions have gone before, if one could only know how to look for them, use Nailgun.

Other ways to improve on script performance is to start fsc at system boot, so it will be available for scripts, and use -savecompiled, to avoid repeated compilation of scripts.

EDIT

You mention -client mode, but I think that's really not a good choice. The will give you a slower Scala compiler, and do little to improve the startup time of the compiler itself, if not Java. Much better to have fsc as daemon, running as -server, and/or save compiled scripts with -savecompiled.

Now, I don't know what problems you are having with -client, but I have read that it doesn't work with 64 bits JVM. Might that be your case?

PS: Looking up similar questions, I noticed JRuby has builtin Nailgun support!


I haven't tried this yet, but scala-native promises near-instant startup because it compiles into a native binary. So one solution is to provide it as a number of binary downloads.

http://www.scala-native.org/en/latest/


I just tried to pass the '-client' parameter through Scala to the JVM this way:

#!/bin/sh
exec scala -J-client "$0" "$@"
!#
args.foreach(println)

It seems to work. Daniel C. Sobral wrote that he read that it doesn't work with 64 bits JVM. I don't know, maybe this is outdated. Anyway it seem to drop the startup time a little bit.

Running:

:~$ time /tmp/testScalasScript arg1
arg1

real    0m2,170s
user    0m2,228s
sys     0m0,217s

This was the fastest run of just a couple of tests. Without it it takes up to 0.5s longer. But this was really a quick test and should be done more systematically to come to meaningful results.

Wasn't there a way to make Scala compile and save the compilation result at the first run of the script for faster reuse? But I don't no for sure at this point of time.

UPDATE: I just saw that on 'java -help' the option '-client' is not documented (anymore?). Anyway there is no error thrown (which is done on usage of unexisting options). So I am not sure if the '-client' option really has consequences.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜