First of all I should mention that I’m aware of the fact that performance optimizations can be very project specific. I’m mostly not facing these special issues right now. I’m facing a bunch of performance issues with the JVM itself.
I wonder now:
- which code-optimization make sense
from a compiler perspective: for
example to support the garbage
collector I declared variables as
final – very much following PMD’s
suggestions here from Eclipse. - what best practices there are for: vmargs,
heap and other stuff passed to the
JVM for initialization. How do I get
the right values here? Is there any
formula or is it try and error?
Java automates a lot, does many optimization on byte-code level and stuff. However I think most of that must be planed by a developer in order to work.
So how do you speed up your programs in Java? 🙂
Advertisement
Answer
I see this a lot. The sequence generally goes:
-
Thinking performance is about compiler optimizations, big-O, and so on.
-
Designing software using the recommended ideas, lots of classes, two-way linked lists, trees with pointers up, down, left, and right, hash sets, dictionaries, properties that invoke other properties, event handlers that invoke other event handlers, XML writing, parsing, zipping and unzipping, etc. etc.
-
Since all those data structures were like O(1) and the compiler’s optimizing its guts out, the app should be “efficient”, right? Well, then, what’s that little voice telling one that the startup is slow, the shutdown is slow, the loading and unloading could be faster, and why is the UI so sluggish?
-
Hand it off to the “performance expert”. With luck, that person finds out, all this stuff is done in the recommended way, but that’s why it’s cranking its heart out. It’s doing all that stuff because it’s the recommended way to do things, not because it’s needed.
-
With luck, one has the chance to re-engineer some of that stuff, to make it simple, and gradually remove the “bottlenecks”. I say, “with luck” because often it’s just not possible, so development relies on the next generation of faster processors to take away the pain.
This happens in every language, but moreso in Java, C#, C++, where abstraction has been carried to extremes. So by all means, be aware of best practices, but also understand what simple software is. Typically it consists of saving those best practices for the circumstances that really need them.