PATCH: Speed up direct string concatenation by 20+%!

Steve Holden steve at holdenweb.com
Thu Sep 28 22:33:04 EDT 2006


Larry Hastings wrote:
> This is such a long posting that I've broken it out into sections.
> Note that while developing this patch I discovered a Subtle Bug
> in CPython, which I have discussed in its own section below.
> 
[...]
> ______________
> THE SUBMISSION
> 
> I don't know the protocol from this point out; should I email the patch
> somewhere?  Put it up on a web page?  Post some diff output?  (Or just
> forget about it entirely?)
> 
> Also, for what it's worth: I fixed the .dsp so pythoncore builds under
> VC6 again.  I would be happy to submit that separately.  (What can I
> say, old habits die hard.  I can't stand the newer Microsoft IDEs.)
> 
> 
> Cheers,
> 
> 
> /larry/
> 
> p.s. No, I haven't looked at a Unicode port yet.  If there's interest
> in
> this patch at all, I might take a stab at it.
> 
A fairly short reply: you should diff your source against the current 
SVN repository and lodge that diff as a patch on SourceForge. It 
wouldn't hurt to let one or two developers know, thought they *might* 
pick it up without.

Your suggested bug isn't, I think a real bug in the current 
implementation because as I understand it Python strings do always 
include a trailing null byte to act as a terminator when the string is 
passed to C code in extensions.

Nice idea, though. You might also see how it does on tasks like

s = ""
for i in range(100000):
     s += "a"

since I believe that's the main culprit in increasing the O(). Also note 
that some optimisation has recently been performed on string 
concatenation, which I presume your code has already taken into account.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb       http://holdenweb.blogspot.com
Recent Ramblings     http://del.icio.us/steve.holden




More information about the Python-list mailing list