tag:blogger.com,1999:blog-8712770457197348465.post3210052969936183829..comments2024-03-28T02:47:19.159-07:00Comments on Javarevisited: 5 Coding Tips for Improving Performance of Java applicationjavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-8712770457197348465.post-28371225543309883332011-06-02T09:42:07.791-07:002011-06-02T09:42:07.791-07:00I don't see the "value" of referring...I don't see the "value" of referring to these tips as "performance" improvements. Optimizations such as removing invariants from loops are fairly universal in just about all modern languages. Divide by two is usually executed via a shift, so you can and should keep your code clean and readable. This article needs a large heading that says "DO NOT IMPLEMENT".Ericnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-78614924833047048632011-03-10T05:26:27.211-08:002011-03-10T05:26:27.211-08:00lots of Anonymous comment but some of them are rea...lots of Anonymous comment but some of them are really great , thanks for for your open feedback guys, yes in today's highly optimized JIT these might be done automatically but I see the value of being known about this.<br /><br />Thanks<br />Javinjavin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-38017285290145413772011-03-10T05:08:39.420-08:002011-03-10T05:08:39.420-08:00Did you know that your optimizations are counterpr...Did you know that your optimizations are counterproductive ?<br /><br />- All modern processors are able to divide by 2 as fast as a bit shift. I just benchmarked the performance difference between the two, and I can manage to perform as much divide by two operations than shifting bit operations in the same amount of time in java.<br /><br />- Did you know that the java compiler automatically Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-83902304504330244962011-03-10T02:07:54.421-08:002011-03-10T02:07:54.421-08:00another approach for #5 is
for (int i=0, j=vector....another approach for #5 is<br />for (int i=0, j=vector.size(); i < j; i++)<br /><br />the point is to avoid the creation of a variable just to store the number of elements of vector (kinda old school isnt it?)Danilohttps://www.blogger.com/profile/15981472914099858893noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-59109155607575663142011-03-10T01:52:17.908-08:002011-03-10T01:52:17.908-08:005.) is just complete BS: have you ever heard of It...5.) is just complete BS: have you ever heard of Iterators? ...and if not, have you ever looked at actual, real-world implementations of #size? Not surprisingly, they hardly ever perform some expensive calculations, but usually just return the 'count' field.<br /><br />And: read the last section of the previous comment, and stop doing such optimizations.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-47580994855229339932011-03-10T01:14:07.819-08:002011-03-10T01:14:07.819-08:00None of these tips will matter when using a modern...None of these tips will matter when using a modern JVM (Hotspot, JRockit, J9), as the JVM will make all those optimizations for you whenever they are applicable. E.g. take #3, the JIT compiler can easily (and will) figure out if your class/method is final, without the need for you to declare it, and generate code accordingly. Should you later load a class that changes this state the JVM will Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-90730927837404797352011-03-10T00:54:55.432-08:002011-03-10T00:54:55.432-08:00@Anonymous
About 1: Whenever you write '*2...@Anonymous<br /><br />About 1: Whenever you write '*2' or '/2', I would say!<br /><br />About 2: The internal char-array will only be resized when the internal buffer "overflows", i.e. depending on your situation.<br /><br />In principle you are right: Code should be readable for a human being, not for the compiler.<br /><br />And "don't optimize prematurely!&Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-52249002170023335792010-10-23T10:35:35.008-07:002010-10-23T10:35:35.008-07:00About 1 - How many times do you know ahead when yo...About 1 - How many times do you know ahead when you are multiplying or dividing by 2 ?<br />2 - is only needed when doing runtime string manipulation, and you must ensure it capacity, otherwise you will sure have penalty in peroformance by the char array resizing<br /><br />4 - Doesn't not sustaint an argument at all, you should try to create object and avoid static methods, because the JIT Anonymousnoreply@blogger.com