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

C2 does not optimize String.charAt loop well

XMLWordPrintable

      Originally reported by [~liach].

      Attached Benchmark.java demonstrates that String.charAt is significantly slower than StringBuilder.charAt for the same String:

      java -XX:CompileCommand=dontinline,Benchmark::test* Benchmark.java
      CompileCommand: dontinline Benchmark.test* bool dontinline = true
      testString() took 1363 ms
      testStringBuilder() took 671 ms

      Even with -XX:-UseSuperWord -XX:LoopUnrollLimit=0 -XX:-UseLoopPredicate -XX:-RangeCheckElimination the difference is significant.

            Unassigned Unassigned
            thartmann Tobias Hartmann
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: