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

Debug statements cause significant performance hit even when not printed

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.3.0
    • 1.0
    • client-libs
    • kestrel
    • generic
    • generic

      X-Authentication-Warning: capra.eng.sun.com: amith set sender to ###@###.### using -f
      Date: Fri, 07 May 1999 11:44:08 +0200
      From: Matthias Pfisterer <###@###.###>
      X-Accept-Language: en
      MIME-Version: 1.0
      To: Java Sound <###@###.###>
      Subject: [javasound] possible performance gain in JavaSound 0.86
      Content-Transfer-Encoding: 7bit

      Hi,

      Thank you for JavaSound 0.86!

      I am developing an application which makes heavy use of audio playback.
      In fact, it does a multi-channel mixing of diverse audio files.

      Doing a simple profiling on this application gives an interesting
      result:

      CPU SAMPLES BEGIN (total = 150034) Thu May 06 17:21:23 1999
      rank self accum count trace method
         1 11.08% 11.08% 16621 12199 java/lang/StringBuffer.append
         2 10.45% 21.53% 15675 12209 java/lang/StringBuffer.append
         3 4.15% 25.68% 6226 12212
      com/sun/media/sound/CircularBuffer.write
         4 2.62% 28.30% 3931 12201 com/sun/media/sound/MixerChannel.write
         5 2.57% 30.86% 3849 12129 java/lang/Integer.toUnsignedString
         6 2.28% 33.15% 3427 12264 java/lang/Object.toString
         7 2.08% 35.23% 3123 12211 java/lang/StringBuffer.toString
         8 1.45% 36.68% 2174 12200 java/lang/StringBuffer.toString
         9 1.35% 38.03% 2030 18612 com/sun/media/sound/MixerChannel.<init>
        10 1.30% 39.33% 1949 8523 java/lang/String.<init>
        11 1.22% 40.55% 1827 15031 java/lang/StringBuffer.setLength
        12 1.18% 41.73% 1774 12269 java/lang/StringBuffer.toString
        13 1.14% 42.87% 1712 15034 com/sun/xml/tree/AttributeSet.<init>
        14 0.93% 43.80% 1393 18427 java/lang/StringBuffer.append
        15 0.89% 44.69% 1337 15032 java/lang/StringBuffer.toString


      The first two positions in the list, StringBuffer.append, which together
      make more than 20 % of the runtime of the programm, are called by
      com.sun.media.sound.CircularBuffer.write() and
      com.sun.media.sound.MixerChannel.write(). Looking at the code, it turns
      out that there are constructs like this:

      Printer.printTrace("> MixerChannel.write(b: " + b + " off: " + off + "
      len: " + len);

      That is, strings with debugging information are assembled always and
      passed to the class Printer, which decides whether they are actually
      output.

      Positions 5, 6, 7 and possibly other also come from these instructions.
      So, by removing them there should be a performance gain of about 30 %.

      To users, I recommend the following procedure:
      1. decompile the classes com.sun.media.sound.*
      2. comment out the Printer.* statements, at least in the heavily-used
      functions MixerChannel.write() and CircularBuffer.write().
      3. recompile the changed classes.
      4. put them into the jar file, replacing the old versions.

      To the JavaSound implementors, I suggest a change in coding practice.
      The statements Printer.xx can be replaced by something like the
      following:

      if (DebugSettings.TraceXY) { System.out.println(...); }

      public class DebugSettings
      {
      // perhaps also programmatically modifyable
      public static boolean TraceXY = true;
      public static boolean TraceYZ = false;
      }

      Done this way, the time-consuming assembling of debugging information is
      executed only if it is really desired. In addition, in a release version
      the Trace.. variables in DebugSettings can be made final. This will
      allow the compiler to completely throw out the debugging code if the
      variable values are false.

      Another note: It would be nice to have the real source code of JavaSound
      to investigate on further improvements. Is it possible to get it under
      conditions of the Community license?


      Matthias Pfisterer
      =====================================================================
      To subscribe/unsubscribe, send mail to ###@###.###
      JavaSound Home Page: http://java.sun.com/products/java-media/sound/

            jborgerssunw Jan Borgersen (Inactive)
            kkytlesunw Kara Kytle (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: