Skip to main content

Start quicker by tuning JVM and javac

13 replies [Last post]
maksym_shostak
Offline
Joined: 2007-07-17
Points: 0

Hello.

I'm searching the ways to reduce startup time of my
small desktop application. I'm searching among Java VM
and javac compiler options.

For example, seems that following could help:

1. java -client (Select the Java HotSpot Client VM. In general,
the server VM starts up more slowly than the client VM, but
over time runs more quickly.)

2. javac -g:none (Do not generate any debugging information)

3. java -Xms, -Xmx (and other performance tuning options).

I look forward to hearing your thoughts.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
lowecg
Offline
Joined: 2004-12-20
Points: 0

If you only have the JRE installed then the server VM will not be available.

One option that can make a significant difference to the startup time is -Xverify:none

Obviously use this with some degree of caution since it turns off class byte code verification.

lowecg
Offline
Joined: 2004-12-20
Points: 0

General question - I'm seeing quite a few posts around discussing Java start up times.

Does anyone know if there is an official benchmark that can be used to measure start up times for desktop applications, web start apps and applets?

dleskov
Offline
Joined: 2003-06-27
Points: 0

We have some application startup time benchmarks, but they are not official, we use them internally for (regression) testing of our Startup Optimizer. I could post a few bits of methodology (disk cache cleanup) here if you are interested.

lowecg
Offline
Joined: 2004-12-20
Points: 0

Yes please, anything you could give me would be greatly appreciated.

Cheers,

Chris.

dleskov
Offline
Joined: 2003-06-27
Points: 0

We have a special mode in our JVM in which it measures the length of the different phases of startup, calculates working set size, counts the number of page faults, and so on. I think Sun may have done something similar, so maybe you can get that by rebuilding the OpenJDK?

For measuring the overall startup times on HotSpot, we patch the test programs so that they exit as soon at the main() method receives control, or when the main window is displayed, etc.

You also have to remove the application and the JRE from disk cache if you want to measure cold startup. There are three options on Windows:

1. Remove everything from %windir%\Prefetch and reboot.

2. Run a memory-hungry task (our night build works perfectly :) )

3. Write a small memory eater. Aggressive ones can make Windows unstable though.

Make sure no Java app using the same JRE is launched on system startup or login.

kamaltiwari123
Offline
Joined: 2008-11-17
Points: 0

hi ,
i am kamal.l am little bit confused that , what is the need to remove files from prefetch and boot directory.

plz try to explain it.

looking forward to hearing you.

thanks
regards
Kamal

keeskuip
Offline
Joined: 2003-06-17
Points: 0

You could create your jar with the option '-i'.

-i = generate index information for the specified jar files

Classloading from that jar will be faster.

lowecg
Offline
Joined: 2004-12-20
Points: 0

What version of the JVM are you using?

I've had favourable experiences with the JVM Quick Starter enhancement in the up coming 6.0u10 release (now in the RC stages) - this improves cold start times on Windows.

https://jdk6.dev.java.net/

Cheers,

Chris.

denka
Offline
Joined: 2003-07-06
Points: 0

I'm not sure if it works anymore, but some while ago people were placing class files in a JAR with no compression to speed up class loading. Class loading does slow things down on the start-up. This also hints at application design, where main application window would appear sooner the less classes it needs to load and the lesser number of objects it has to instantiate. Thus, try deferring initialization of non-essential things, but not to the degree where everything loads on demand: that might hurt perception of responsiveness. And now we arrived at the most important thing: perception of performance. Your customer will wait a little and will not be outraged about it if you provide some feedback. Splash screen with progress indicator (while you eagerly load all essential resources and restore application state) is a must.

mrmorris
Offline
Joined: 2006-07-26
Points: 0

Exactly. Will someone please explain this to the NetBeans team. The current lazy loading trend does not assist in perceived performance.

linuxhippy
Offline
Joined: 2004-01-07
Points: 0

Compiler options won't help that much I fear.

Best you can do is install JDK6u10-beta (the most recent build) and enable quickstarter, this should help much more than anything else.

The client-jvm should be default anyhow ... oh well wait ...on Linux with 2CPUs and 2GB ram its now the server compiler, because this is considered a server-class machine. Really stupid, my Laptop has already 3GB ram!

lg Clemens

maksym_shostak
Offline
Joined: 2007-07-17
Points: 0

> The client-jvm should be default anyhow ...
> lg Clemens

Not only on Linux.
See server-class machines detection at
http://java.sun.com:80/j2se/1.5.0/docs/guide/vm/server-class.html

demonduck
Offline
Joined: 2008-03-14
Points: 0

More stupid engineering -- if it's a server, wouldn't there be a System Administrator that would make sure that the server JVM is the default?

Average machines these days have over 2gig mem and more than 2 processors.

May I suggest that the Java Dev Team is trying to make Java into some sort of Artificial Intelligence entity that tries to anticipate the users needs. It's easier and simpler to let the human figure it out using standard and conventional use patterns.