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

RFE: StringBuffer speed enhancement

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.1
    • core-libs
    • x86
    • windows_2000



      Name: rmT116609 Date: 05/01/2003


      A DESCRIPTION OF THE REQUEST :
      I propose some changes in the String/StringBuffer - code:

      1.) add a package local method to the String-class

            void getChars( char dst[], int dstBegin ) {
                    System.arrayCopy( value, offset, dst, dstBegin, count );
            }


      2.) check and change the StringBuffer-class to replace calls
             str.getChars( 0, len, value, count )
           to
              str.getChars( value, count )
           there are some of these calls, most of them can be changed.


      I think, this '0' in the parameter-list is one of the most often
      redundantly passed and best checked 0's in the java-world.

      This few superflous statements are a bigger part of the
      fixed cost of string-buffer appending, besides growing the buffer
      and the actual copying.



      JUSTIFICATION :
      Yes, maybe a smart Hotspot VM can inline away some of the old
      getChars()-code, but still the modified code is faster than before.
      And all not so smart JVM's will benefit too - and older JDK's should also...

      When saving cpu-cycles is so central and so simple, it should be done.


      PS: It would be easy to set up a simple benchmark which proves
      'StringBuffer-appending speed-up by 50%'



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      some speed-up of StringBuffer.append( string )
      more noticable effect for shorter strings
      (Review ID: 185141)
      ======================================================================

            mmcclosksunw Michael Mccloskey (Inactive)
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: