Optimize away string creation when using java.util.Logging APIs

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Future Project
    • Priority: P4
    • None
    • Affects Version/s: 1.4.2
    • Component/s: core-libs



      Name: rmT116609 Date: 11/12/2003


      A DESCRIPTION OF THE REQUEST :
      Currently, if the Logging APIs force the developer to prefix all of their calls to log.<whatever> (i.e., log(), info(), config(), etc) with a test to determine if the request log level is currently active if they wish to avoid unncecessary String allocation. For example:

       if (log.isLoggable(Level.FINE))
          log.fine("Some trace msg: x="+x+" y="+y);

      JUSTIFICATION :
      Unnecessary allocation of strings increases runtime memory footprint and may require more cycles to be spent on GC. Code is also considerably less readable.



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      It would greatly improve code readability and improve the runtime footprint of the application if the compiler and/or the runtime environment was smart about calls to the Logging APIs and would essentially insert the conditional test code during compilation. This way, a developer could simply write:

       log.fine("Some trace msg: x="+x+" y="+y);

      and not worry about having to protect the call when the specified logging level was not active.
      ACTUAL -
      Currently, if a developer does not do the test, the runtime environment dutifully creates all the strings whether or not they are ever logged.
      (Incident Review ID: 225336)
      ======================================================================

            Assignee:
            Unassigned
            Reporter:
            Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: