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

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

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: New
    • Priority: P5
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: tools
    • Labels:
      None

      Description

      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.

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated: