Path: csiph.com!aioe.org!.POSTED!not-for-mail From: =?UTF-8?Q?Arne_Vajh=c3=b8j?= Newsgroups: comp.lang.java.programmer Subject: Re: A third easy performance optimisation needed Date: Thu, 13 Jul 2017 19:39:54 -0400 Organization: Aioe.org NNTP Server Lines: 43 Message-ID: References: <87d1946ab3.fsf@munus.decebal.nl> <7cb2594a-bf4e-43bd-9d2b-20845b05b71e@googlegroups.com> NNTP-Posting-Host: PBuS014lhzVyHjLbXmo/ZQ.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.java.programmer:36921 On 7/13/2017 8:48 AM, Eric Douglas wrote: > On Thursday, July 13, 2017 at 7:41:39 AM UTC-4, Eric Sosman wrote: >> I'm not sure what you intend to say about `final', but I >> hope you're familiar with Brian Goetz' thoughts on the matter: >> >> https://www.ibm.com/developerworks/java/library/j-jtp04223/index.html#N10087 >> >> https://www.ibm.com/developerworks/java/library/j-jtp1029/index.html > > So final classes and methods may not improve performance or definitely won't improve performance? I think the conclusion is that there is no reason to expect a performance improvement. The actual performance may vary between Java vendor (Oracle, IBM, Azul etc.), version and platform. > Even if they do improve performance, if the improvement is insignificant it is a valid point > you should not do it unless you definitely don't want the class extended or method overridden. > Oracle does use it occasionally for that reason, notably in the String class. There are good reasons to use final. Good reasons relating to the OO design. > So final variables don't affect performance either way? Not sure. I am not a JVM expert like Goetz. My guess would be that it is the same: no reason to expect a big performance difference, but other reasons within design exist. > I do use the Eclipse option to automatically declare variables > final which are assigned exactly once. That is an increasingly popular trend. > These articles were written in 2002-3. I wonder if it's all still relevant. The JIT compilers optimizer has become even smarter than it was in 2003. The smarter the optimizer is the dum,ber it is to try and manual optimize the code. Arne