Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8360517

C2: Incomplete ArrayList foreach optimization

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • None
    • hotspot

      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.

            Unassigned Unassigned
            shade Aleksey Shipilev
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: