-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
None
Noticed this one with arrays vs ArrayList iteration benchmarks. See attached file for a complete reproducer and generated code analysis.
In short, ArrayList for-each iteration is more expensive than for-index iteration. The proximal reason for performance difference are the microarchitectural effects processing a larger loop (JDK-8281586), but the root issue here is that for-each produces less efficient hot loop. It is already somewhat miraculous C2 is able to cut out _a lot_ of ArrayList$Itr iterator fluff, and only this bit seems to be remaining.
In short, ArrayList for-each iteration is more expensive than for-index iteration. The proximal reason for performance difference are the microarchitectural effects processing a larger loop (JDK-8281586), but the root issue here is that for-each produces less efficient hot loop. It is already somewhat miraculous C2 is able to cut out _a lot_ of ArrayList$Itr iterator fluff, and only this bit seems to be remaining.
- relates to
-
JDK-8281586 x86: Default to larger OptoLoopAlignment
-
- Open
-