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
zero.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@ant.apache.org
For additional commands, e-mail: dev-h...@ant.apache.org

Reply via email to