[Python-ideas] Create a StringBuilder class and use it everywhere

Masklinn masklinn at masklinn.net
Thu Aug 25 18:50:51 CEST 2011

On 2011-08-25, at 18:40 , Antoine Pitrou wrote:
>> The most popular (as from what I can see) thing right now where people start seeing
>> that += is slow is when they try to do that on PyPy (which doesn't have hack like CPython,
>> who is still slow) and ask "why my pypy code is sooooo slow".
> Different implementations having different performance characteristics
> is not totally unexpected, is it?
> (and I'm sure the PyPy developers wouldn't mind adding another hack)
This one can not be done, as it relies on knowing there's only one reference
to the string (so it can be realloc'd in place), therefore on using a
refcounting GC.

Since Pypy does not use refcounting, it can't do that as a rule (it might be
possible to handle it for a limited number of cases via escape analysis,
proving there can be only one reference to the string, but I'd say there
are more interesting things to use escape analysis for).


> Wish CPython didn't contains hacks which make str += str faster,
> sometimes, depending on refcounting details :(

More information about the Python-ideas mailing list