|
Pankaj Kumar's WeblogRandom thoughts, musings, experiences, ideas, and opinions |
June 27, 2004Who (or What) is slowing down my Java App Startup?Few weeks ago I got an email message from my colleague Craig Bryant asking about potential fix for an annoying pause during startup of his Java program that did some crypto during initialization. He also attached his code, pin-pointing the problem to the first invocation of the call I compiled and executed the program on my old and rusty W2K desktop (a Pentium 350MHz box), and confirmed the delay. I also found that the delay was cut by almost half by just switching from J2SDK1.4.1 to J2SDK1.4.2. Not surprising given the impressive optimizations reported in J2SE 1.4.2. Running the program on a more modern machine (say, a 2.0GHz box) further reduced the delay to a more acceptable sub-second range. I attributed this to slow-but-necessary security intialization overhead and forgot about it. Craig later reported that he profiled the code and found that most of the delay was due to signature verification. This made sense. Invocation of Lateron, after reading the recommendation to run the server JVM for better performance (which made sense anyway, as the original program was to run as a server program), I tried the same program with java -server, only to find that startup delay was worse than without -server option, with a factor of 3.5! (a 0.9 sec. delay became a 3.2 sec. delay). Again, an explanation is not hard to come by: -server option causes the JVM to compile all the code used in verifying the signed jar to native code, even if the verification takes place only once. And because of this, the performance gain of running native machine instructions do not offset the time spent in doing the byte code to native code translation. Although the previous story is in the context of crypto operations, the general observation that signed jar files introduce human perceptible startup delays, applies to many more situations. This delay is proportional to the size of the signed jar and not the size of classes that get used from this jar file. For example, the following HelloWorld.java program: takes around 280 milli seconds to execute when class This is something to keep mind if you plan to deliver signed jar files! Posted by pankaj at June 27, 2004 12:45 PMComments
Post a comment
|
|
|
Disclaimer: Views expressed here are my own and do not represent those of my employer.
© 2001-2005 Pankaj kumar. All Rights Reserved. |
|