JDK-4857141 : RFE: StringBuffer speed enhancement
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 1.4.1
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-05-01
  • Updated: 2003-05-01
  • Resolved: 2003-05-01
Related Reports
Duplicate :  
Description

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) 
======================================================================

Comments
EVALUATION This was already done as part of 4857141. ###@###.### 2003-05-01
01-05-2003