Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Machine > Re: Optimising ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 5 Topic 801 of 808
Post > Topic >>

Re: Optimising StringBuilder

by "Boudewijn Dijkstra" <usenet@[EMAIL PROTECTED] > Apr 19, 2008 at 12:05 AM

Op Fri, 04 Apr 2008 23:19:34 +0200 schreef Roedy Green  =

<see_website@[EMAIL PROTECTED]
>:
> I'm curious just how clever HotSpot is about optimising StringBuilder,=


Why?  If string manipulation is your main bottleneck, then probably it's=
  =

better not to use StringBuilder.  Or to do less string manipulation.  Or=
  =

both.

> Here are some possible optimisations.
>
> 1. when allocating the StringBuilder, compute the length where
> possible to create the exact size.

This will cost performance if the programmer already chose an acceptable=
  =

guesstimate.

> 2. when doing append ( "xxx");
> append ("yyy");
> convert that to append( "xxxyyy");

I don't consider this an optimisation, as it will cost memory (and  =

performance if the code isn't used enough) at the expense of tasks which=
  =

could very well be much more im****tant than string manipulation.

> 3. when doing toString, if char[] internally is the correct length,
> steal that array to use in the string, and lazily make a copy (which
> should be rarely needed.)

Interesting.  Also, it should be possible to determine the usage of the =
 =

char[], and so to not keep a reference around when it isn't needed.

> 4. convert append ( " " ) to append ( ' ' );

The source compiler should have done this.  Otherwise, if the referenced=
  =

string is a variable (which varies in length), it is probably not feasib=
le  =

(because something will need to check the length anyway).

> 5 convert  append ( a + b + c ) to append (a ); append (b); append
> (c);

Should have been done by the source compiler.  Even if you have code lik=
e  =

this:
	StringBuffer buf =3D new StringBuffer();
	buf.append(a).append(b).append(c);
	builder.append(buf);

> If it is not clever, then consider how you might implement these with
> a BYTE CODE optimiser.



-- =

Gemaakt met Opera's revolutionaire e-mailprogramma:  =

http://www.opera.com/mail/
 




 5 Posts in Topic:
Optimising StringBuilder
Roedy Green <see_websi  2008-04-04 21:19:34 
Re: Optimising StringBuilder
Roedy Green <see_websi  2008-04-04 22:14:42 
Re: Optimising StringBuilder
"Boudewijn Dijkstra&  2008-04-19 00:05:37 
Re: Optimising StringBuilder
Roedy Green <see_websi  2008-04-20 10:44:22 
Re: Optimising StringBuilder
"Boudewijn Dijkstra&  2008-04-20 13:57:38 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 5 19:05:43 CDT 2008.