[Python-Dev] Optimized string concatenation

Adam Souzis adamsz at gmail.com
Tue Aug 3 19:46:49 CEST 2004


> > > Why do people want this so badly?

As someone relatively new to python, it struck me as a language wart
that i had to learn the form '"".join() as the proper way to do string
concatenation. It violates the principles of OOWTI and its certainly
not the obvious way to do string concatenation. This patch does not
cover all the cases so we're still stuck with join(), but as long as
it is not a documentated "feature" it will harmlessly improve the
performance of countless lines of code where the coder is either
untrained or too lazy to use join().  If its documented it'd just
muddy the waters vis a vis join(), besides the issues with other
Python implementation mentioned here.

-- adam

On Tue, 03 Aug 2004 08:27:26 -0700, Guido van Rossum <guido at python.org> wrote:
> > I spent a *long* time reviewing and testing this patch.  The code is
> > clean.  The concept works.  It delivers significant, measurable
> > benefits.  The standard library itself has existing use cases.
> > Every benchmark I tried showed results.  The patch was not approved
> > prematurely!
> 
> Yes it was.  You know I am interested in this kind of decision
> (otherwise you'd have just checked it in) so you should have left the
> honor to me.
> 
> > > I am going to make up a new rule here, and state that
> > > implementation features that affect not just the running speed but
> > > the O() rate for certain algorithms should be considered language
> > > features, because any implementation will be required to implement
> > > them in order to ensure code portability.
> >
> > Even list.sort() does not guarantee specific O() rates.  Currently,
> > the fastest way to write a merge(a,b) is sort(a+b).  That relies on
> > the current implementation recognizing that a and b are already
> > sorted and doing a linear time concatenation.
> 
> That's a much more obscure case.  The string concatenation hack will
> affect a significant fraction of all code.
> 
> > > Why do people want this so badly?
> >
> > Because the a=a+b form occurs everywhere, not just in newbie code.
> > It is in the standard library, it shows up naturally in SAX, and it
> > is often the most clear way to express an idea.
> 
> And in 99% of those cases nobody cares about performance.
> 
> 
> 
> --Guido van Rossum (home page: http://www.python.org/~guido/)
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/adamsz%40gmail.com
>


More information about the Python-Dev mailing list