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

(fmt) Formatter should avoid repeated parsing of format strings

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_2000

      Description

      A DESCRIPTION OF THE REQUEST :
      A profile of an application heavily using String.format revealed that over 90% of the String.format runtime is spent on parsing the format strings. The application uses no more than 10-20 different format strings, each of which are used several million times.

      JUSTIFICATION :
      If java.util.Formatter could avoid repetitive parsing of format strings, a significant (90% in this case) of runtime could be saved.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Either some sort of PreparedFormatter should be provided that reuses a previously parsed format string, or the Formatter class should cache format strings internally.
      ACTUAL -
      java.util.Formatter (re)parses format strings for each use.

      ---------- BEGIN SOURCE ----------
      class T {
         public static void main (String[] args) {
            for (int i = 0;i < 1000000;i++) {
               System.out.format ("%d. %s%n",i,"Hello world!");
            }
         }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      None identified.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Imported:
              Indexed: