Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #8118

Re: StringBuilder

From Jan Burse <janburse@fastmail.fm>
Newsgroups comp.lang.java.programmer
Subject Re: StringBuilder
Date 2011-09-18 09:54 +0200
Organization albasani.net
Message-ID <j54841$92q$1@news.albasani.net> (permalink)
References <96f358c8-a024-40db-b60b-300186c2f813@o10g2000vby.googlegroups.com> <j41fik$3qb$1@news.albasani.net> <j52jgd$iij$1@dont-email.me> <vp7a77lp3e5oe4h79pnmv95vb4lu13spmc@4ax.com> <GeednbWNqODBGOjTnZ2dnUVZ_rqdnZ2d@posted.palinacquisition>

Show all headers | View raw


Peter Duniho schrieb:

> In any case, if Java does _not_ implement it that way, I suspect that's

Well, I wouldn't say its a matter of *Java*. Its a matter
of the given JDK how it is implementented. *Java* defines
the contract but there are many implementations.

 From my post you can read off the following findings:

    Oracle: Always does a copy (I only checked rt.jar,
                                not some alt-rt.jar).
    OpenJDK: Always does a copy.
    Harmony: Most of the time does a sharing and
             flags the builder (Similarly like you
                                describe the .NET implementation)

But beware the list is not complete, for example I
didn't check the Apple classes.jar or IBM's rt.jar.
And also the finding only holds for JRE 1.6, and can
change at any time if the provider of the JRE decides
so. Or might be different for 32-bit and 64-bit etc..

 > different decision-making process rather than ignorance.  In other
 > words, they have already considered whether it's a worthwhile
 > optimization and decided

There is not only a plurality of *they* as can be seen
from above, but there is also a plurality what means
*worthwhile*. An implementation with a more reference
implementation character, like for example the Oracle
JRE, might take the simple route. Since the focus is
then more on functional requirements than on non-
functional requirements.

 > Which strongly suggests that anyone worrying a priori
 > about the performance of StringBuilder before they have
 > demonstrated it's an actual bottleneck in their program
 > is wasting their time.

I guess it is more about performance tuning than removing
bottlenecks. And any performance gain is only seen in
programs that make heavy use of StringBuilder. Such
measurements have already been done over and over. See
for example (not exactly measurig toString()):

   +=: 546 ms
   StringBuilder, default initial capacity: 30ms
   StringBuilder, exact initial capacity: 10ms

http://christian.bloggingon.net/archive/2008/09/06/performance-vorteile-bei-der-verwendung-von-stringbuilder.aspx

But measurements in detail will vary depending on JDK
and machine. But whether one JDK changes the measurment
fundamentally depends very much of the available
algorithms for the functional requirements and how
these algorithms behave non-functionally.

But I would say the consumers of JDKs are we the
programmers, so it is good to measure, inspect and
debate JDKs and not blindly trust any *they*.

Bye

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Re: StringBuilder Stanimir Stamenkov <s7an10@netscape.net> - 2011-09-17 19:56 +0300
  Re: StringBuilder Jan Burse <janburse@fastmail.fm> - 2011-09-17 20:35 +0200
  Re: StringBuilder Roedy Green <see_website@mindprod.com.invalid> - 2011-09-17 15:34 -0700
    Re: StringBuilder Jan Burse <janburse@fastmail.fm> - 2011-09-18 01:33 +0200
      Re: StringBuilder Jan Burse <janburse@fastmail.fm> - 2011-09-18 01:56 +0200
      Re: StringBuilder Roedy Green <see_website@mindprod.com.invalid> - 2011-09-17 20:58 -0700
    Re: StringBuilder Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-09-17 22:44 -0700
      Re: StringBuilder Jan Burse <janburse@fastmail.fm> - 2011-09-18 09:54 +0200
        Re: StringBuilder Jan Burse <janburse@fastmail.fm> - 2011-09-18 09:59 +0200
        Re: StringBuilder Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-09-18 07:28 -0700
      Re: StringBuilder Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-18 08:15 -0400
        Re: StringBuilder Jan Burse <janburse@fastmail.fm> - 2011-09-18 15:32 +0200
          Re: StringBuilder Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-18 09:50 -0400
            Re: StringBuilder Stanimir Stamenkov <s7an10@netscape.net> - 2011-09-18 17:08 +0300
            Re: StringBuilder Jan Burse <janburse@fastmail.fm> - 2011-09-18 22:13 +0200
              Re: StringBuilder Jan Burse <janburse@fastmail.fm> - 2011-09-18 22:29 +0200
                Re: StringBuilder Jan Burse <janburse@fastmail.fm> - 2011-09-18 22:39 +0200
      Re: StringBuilder Roedy Green <see_website@mindprod.com.invalid> - 2011-09-19 09:45 -0700

csiph-web