ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Bodewig <>
Subject Re: svn commit: r1066963 - in /ant/core/trunk/src/main/org/apache/tools: ant/ ant/taskdefs/ ant/taskdefs/cvslib/ ant/taskdefs/email/ ant/taskdefs/optional/ ant/taskdefs/optional/depend/ ant/taskdefs/optional/depend/constantpool/ ant/taskdefs/optional/i18n/...
Date Fri, 04 Feb 2011 15:06:05 GMT
On 2011-02-04, Antoine Levy-Lambert wrote:

> Hello Stefan,

> I did not know that using a final variable for the upper bound of a
> loop instead of something.size() makes a difference in terms of
> performance. Interesting.

> I just read the original bug report "Project.fireMessageLoggedEvent
> performance fix" [1] and the one you have addressed [2].

> In an ideal world, should the compiler not do these optimizations for
> us automatically ?

The compiler can not know that size() will always return the same result
during the loop execution - using the external variable makes this
explicit.  So instead of a method call per loop iteration you get a
variable read on a local variable that may even get optimized away as
the variable is known to never change its value.

A smart compiler might see that the variable never gets reassigned so
the final keyword may be redundant.

Most of the places where I have made the changes were one-time
executions or really small loops so the effect is probably close to


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message