Bazaar: Out of memory

James Henstridge james at
Sat May 10 01:59:42 BST 2008

2008/5/10 Andrew Bennetts <andrew at>:
> James Henstridge wrote:
>  [...]
> >
>  > In contrast, each "line_bytes += line" iteration in your version does:
>  >  1. allocate a new string large of length len(line_bytes) + len(line)
>  >  2. copy line_bytes and line into the new string
>  >  3. free the old line_bytes.
>  (Actually, since Python 2.4, "s += 'abc'" is sometimes more efficient:
>  It doesn't sound like you should rely on that particular optimisation though.)
>  I haven't looked at the offending code at all, but how hard would it be for the
>  relevant APIs to accept an iterable of strings instead of a single big string?

Looking at the optimisation in ceval.c, it seems you'll still suffer a
realloc() of the original string (which will be an allocation +
memcpy() on some iterations), and a memcpy() of the other argument.
So it could be a bit faster than what I described, but would still
give quadratic behaviour (albeit slightly better quadratic behaviour).


More information about the bazaar mailing list