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

Consider translating "" + value as String.valueOf(value) directly

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P5 P5
    • tbd
    • None
    • tools
    • None

      This recent optimization manually replaces "" + char with String.valueOf(char): https://github.com/openjdk/jdk/pull/6326

      This was in java.base, so the translated bytecode replaced was a StringBuilder chain. In user code this pattern would emit a call into StringConcatFactory, which would be even more excessive since it'll boil down to a call to String.valueOf in the end after a detour through some MethodHandles.

      Consider a translation where javac replaces this particular concat expression with a call to String.valueOf() regardless of -XDstringConcat strategy. The pattern is common in existing codebases - including the OpenJDK - so if it's not too much trouble it might be a worthwhile startup optimization.

            Unassigned Unassigned
            redestad Claes Redestad
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: