[Python-Dev] Optimization

Stephen J. Turnbull stephen at xemacs.org
Sun Oct 6 12:37:53 CEST 2013


Nick Coghlan writes:

 > I suspect "list" may have been the intended comparison there.
 > "array.array" is another appropriate comparison.  Having bytearray
 > operations differ in algorithmic complexity from those two types
 > would be very strange and surprising

I don't see why.  If you really wanted bytearrays to be similar to
list or array.array in that way, wouldn't you derive them from one of
those types[1] rather than provide a primitive?  Having a separate
primitive makes it easier to implement optimized performance
characteristics.  Isn't that why we have several different kinds of
containers instead of deriving everything from list?

For me, the point about string "+=" being efficient (sometimes) isn't
that it is surprising compared to similar types, it's that it is
surprising for any immutable sequence type.

Footnotes: 
[1]  Or all of them from an ABC.



More information about the Python-Dev mailing list