rpadev said:
Jon,
Could you be a little more specific? Our app has a lrage number of
classes in it and I suspect that many of them are loaded becasue they
reference each other. As I understand it, classes are loaded if they are
referenced and not yet instantiated. Do I have this right? What shoul
dbe my next move?
Uh oh. You're using a naughty word.
"suspect"
That's a big no-no when it comes to performance. Studies have shown that
developer intuition is wrong the majority of the time when it comes to
optimization.
Probably the first thing of all is to measure what's going on. Instead
of guessing, check. As Vladimir pointed out, there are probably actually
two things going on in your situation.
Problem: "My program is slow to start"
Off hand, I'd say that most the time could be from two causes
1) Class loading is slow.
2) Application state and initialization/construction is slow.
So, keeping in mind that there are probably two different things going
on, you'll probably want to start getting measurements of both.
One thing to do is to check/dump the time as the first thing inside of
your main(). Then maybe dump it at the end also.
Another thing to do is to decouple your app's class loading from Java
startup itself. The simple way is to have a bare class that does not
reference any other classes at all. Inside the main of your launcher
stub dump the time, then use reflection to load your real main class.
dump the time again. Then instantiate your main class. Dump the time again.
Start measuring things. Broken apart like that, and with the two
different issues in mind, it should help with profiling.
IIRC, the main thing that might be slowing class loading is static
initializers. See if you have static blocks, or if you have static
variables initialized to a new instance of any classes.
Again, first start by splitting java starting from your classes and look
at where the big numbers fall. Then after that start to hunt down.
*THEN*, after all that is done and you have loads of wall-clock and
profiled measurments, then it will be safe to start thinking about
optimizing and whether or not things will improve your performance.
Since by that point you'll have all sorts of metrics, it will be easy to
A) see what needs improving, and B) see which things have either
negative, positive or negligible.