Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the JVM slow to start?

What exactly makes the JVM (in particular, Sun's implementation) slow to get running compared to other runtimes like CPython? My impression was that it mainly has to do with a boatload of libraries getting loaded whether they're needed or not, but that seems like something that shouldn't take 10 years to fix.

Come to think of it, how does the JVM start time compare to the CLR on Windows? How about Mono's CLR?

UPDATE: I'm particularly concerned with the use case of small utilities chained together as is common in Unix. Is Java now suitable for this style? Whatever startup overhead Java incurs, does it add up for every Java process, or does the overhead only really manifest for the first process?

like image 767
Jegschemesch Avatar asked May 09 '09 21:05

Jegschemesch


People also ask

How can I speed up JVM?

JVM startup performance can be improved in many ways: CDS, straight up tuning, CPU pinning and jlink (since JDK 9) can be good options. AOT (JDK 9, Linux-only) has some rough edges but can be tuned to help small applications.

Why is Java running so slowly?

Slowness of Java programs is primarily because of bad programming practices. But following areas are where Java can be improved. Java libraries are written keeping readability and correctness in mind, not performance. Slow String based operations as Strings are UTF-16 encoded objects and are immutable.


2 Answers

Here is what Wikipedia has to say on the issue (with some references).

It appears that most of the time is taken just loading data (classes) from disk (i.e. startup time is I/O bound).

like image 154
Naaff Avatar answered Sep 22 '22 07:09

Naaff


Just to note some solutions:

There are two mechanisms that allow to faster startup JVM. The first one, is the class data sharing mechanism, that is supported since Java 6 Update 21 (only with the HotSpot Client VM, and only with the serial garbage collector as far as I know)

To activate it you need to set -Xshare (on some implementations: -Xshareclasses ) JVM options.

To read more about the feature you may visit: Class data sharing

The second mechanism is a Java Quick Starter. It allows to preload classes during OS startup, see: Java Quick Starter for more details.

like image 41
Alexandr Avatar answered Sep 24 '22 07:09

Alexandr