Hacker News new | ask | show | jobs
by lneves 6401 days ago
No way JVM starts in under a second: it's more like 2 full seconds on his hardware.

My machine has lower hardware specs than what the article mentions. This is what i get.

$ java -version

java version "1.6.0_10"

Java(TM) SE Runtime Environment (build 1.6.0_10-b33)

Java HotSpot(TM) 64-Bit Server VM (build 11.0-b15, mixed mode)

$ uname -a

Linux lneves-t61p 2.6.27-9-generic #1 SMP Thu Nov 20 22:15:32 UTC 2008 x86_64 GNU/Linux

$ echo "public class Test{public static void main(String[] args) {System.out.println(\"Hello World\");}}" > Test.java

$ javac Test.java

$ time java Test

Hello World

real 0m0.174s

user 0m0.068s

sys 0m0.016s

It seems that you are wrong.

More likely he had some of JVM in the filesystem cache. Vista/OSX will pre-fetch JVM modules even after you reboot (not sure about Linux) if you run Java software and especially if you have 8GB of RAM...

Do you mean Class Data Sharing?

http://java.sun.com/j2se/1.5.0/docs/guide/vm/class-data-shar...

Lets disable it:

$ time java -Xshare:off Test

Hello World

real 0m0.165s

user 0m0.060s

sys 0m0.040s

Not much of a difference.

1 comments

Just repeated your experiment on a MBP 2.2GHz. Got 0.424s real for the first attempt, then ~0.180s for all subsequent. So even on a far slower machine with no caching whatsoever, it's still under half a second :)
No caching? http://java.sun.com/javase/6/docs/technotes/guides/jweb/othe...

OSX employs its own pre-caching similar to Vista.

Think for second: how many various files need to be read off your hard drive for JVM to get started. There are some tools you can use (depends on your platform) that will help you with coming up with an exact list.

That's A LOT of I/O. No hard drive will give you sub-second time.

Does it matter if there's caching though? All modern operating systems cache / prelink / etc. Would you say C has a "30 second lag" because a basic "Hello world" program took 30 seconds to load including how long it takes the computer to start up from cold to run that program? After all, the operating system provides the APIs that C uses.. just as the JVM provides Java's.

If a computer starts an app in, say, about 0.2 seconds every time, it's disingenuous to keep referring to some "2 second lag" since that 2 second lag never really occurs in real use under production conditions. At most, it happens once.

Well... I haven't touched any JVM-based software in a few days on my 2.4ghz MBP with 4GB of RAM. Caches got cleared and pre-fetch "forgot" about it, I guess it figured that the heavy Adobe software I've been running needed it more.

So I just timed hello world (in Java) and it gave me 1.89sec.

That's pretty lame if you ask me. In fact, that's incredibly lame. Imagine if it wasn't just "hello world", but an actual piece of usable code! In fact I can even tell you how long it takes for my Excel parsing tool (Java, command-line based, uses Apache POI) takes to start up on a 100% "cold" machine: about 4 seconds.

I wonder how this simple tool would fare on Linux-based netbooks with total 512MB of RAM and slow CPUs... or something like iPhone.

That's a one-off. Startup times are rarely included in benchmarks since they're not representative of true day to day performance - which is the sort of performance most people care about.

An extra couple of seconds for booting up an entire framework you haven't used for a few days is nothing to worry about. If you were doing performance intensive work, it'd already be all cached and ready to go.