Getting C/C++ performance out of Java

cPerfInJavaRecently, I have watched a live presentation about achieving better performance in Java. C and C++ is still considered as an ultimate exemplar of performance. I remember how Java was terrible in that area 10+ years ago. PC users hated it. High memory consumption, CPU intensive garbage collection etc. Since then a lot has changed, PCs are more powerful, Java is much faster, GC improved significantly but is it the right time for programmers to stop chasing milliseconds of execution and bytes of storage?

This presentation is a view on this topic from one side. As I think it is worth to watch, I would like to share the video and my comment with you.


Original presentation

A video from the live session was published on youtube. I posted it below.

My comment

Spoiler alert! Watch the video first before you read this so you had your own opinion.

The presentation clearly shows that there is a room for improvement for Java programmers to achieve better performance. The techniques we saw were impressive let alone the gain in speed and memory. However, there were a few things that I think has to be deeply considered before going any further.

  1. It is ugly.
    Writing code like this makes it a nightmare for teammates and even ourselves after a few months. I would scream if I saw those bytes operations. Changing the structure a little bit requires analyzing a big part of the code and recalculating bytes to make sure they are shifted and allocated correctly. We had done it before ... then Java was created.

  2. It is not applicable everywhere.
    The presented cases are good ones for such optimizations because they are mostly fix length and well structured. It is not true in all projects and all data structures. I agree it gives a significant improvement overall if the bottleneck is located in such a nice area but if it is not, forget about it and find another way to speed it up.

  3. Is performance improvement worth it in a particular case?
    In a few probably yes. In most cases, I am sure it is not! Majority of systems are doing just fine with the way they were developed. Increasing their performance would be nice, but not in such a big price (see point 1). Agile methodology propagates good enough term instead of excellence. Most things in the world does not have to be perfect, they just need to meet our requirements. That's it. I strongly believe it is better to implement a business feature desired by users instead of fighting with performance when nobody complains about it. In the future, the system will get more powerful hardware anyway or it will be refactored/rewritten or replaced by different software because of business reasons, not performance.

Besides everything I wrote above, I must admit, the presentation was worth watching. It is good to know, what possibilities are out there in Java if they are really needed.