Java Performance Tuning

Java(TM) - see bottom of page

|home |services |training |newsletter |tuning tips |tool reports |articles |resources |about us |site map |contact us |
Tools: | GC log analysers| Multi-tenancy tools| Books| SizeOf| Thread analysers| Heap dump analysers|

Our valued sponsors who help make this site possible
JProfiler: Get rid of your performance problems and memory leaks! 

Training online: Concurrency, Threading, GC, Advanced Java and more ... 

Question of the month: choosing the faster feature

JProfiler
Get rid of your performance problems and memory leaks!

Modern Garbage Collection Tuning
Shows tuning flow chart for GC tuning


Java Performance Training Courses
COURSES AVAILABLE NOW. We can provide training courses to handle all your Java performance needs

Java Performance Tuning, 2nd ed
The classic and most comprehensive book on tuning Java

Java Performance Tuning Newsletter
Your source of Java performance news. Subscribe now!
Enter email:


Training online
Threading Essentials course


JProfiler
Get rid of your performance problems and memory leaks!


Back to newsletter 039 contents

Which way should I write this piece of code to be faster, using feature X or feature Y?

I get a lot of questions like this. I've even written an article or two explaining the performance difference for some types of features, such as this one on the difference between i++ and ++i or this one on the costs of using exceptions in different ways. These are interesting in a pretty low-level kind of way, and occasionally such information can come in useful.

But I can also understand one of my colleagues' response to that "i++ vs. ++i" article. He basically said "get a life". And for basic performance tuning, I pretty much agree with him. The real response to almost all questions like this is to code according to best practices, making your code as readable and maintainable as possible first of all. If you have a couple of alternative ways to code something, don't start thinking about the alternative performance probabilities. Use the more readable option.

Then profile the code using valid and representative test cases to find where the real bottlenecks are, and fix those bottlenecks to be faster. Sure, occasionally the bottleneck will turn out to be where you were asking about one of those alternative features. But most of those alternative features that you could have asked about will not be located in the real bottlenecks. Which means that your code will be that much more readable in most places. And honestly, everyone will be happier in the long run if your code is more readable. Perl programmers find that out pretty quickly.

So the full answer is: Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster. Don't worry too much about performance while you are writing that beautiful code.

The JavaPerformanceTuning.com team


Back to newsletter 039 contents


Last Updated: 2024-08-26
Copyright © 2000-2024 Fasterj.com. All Rights Reserved.
All trademarks and registered trademarks appearing on JavaPerformanceTuning.com are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries. JavaPerformanceTuning.com is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
URL: http://www.JavaPerformanceTuning.com/news/qotm039.shtml
RSS Feed: http://www.JavaPerformanceTuning.com/newsletters.rss
Trouble with this page? Please contact us