The idea behind this patch:
>>> x = range(100) + [1,2,3] + range(90)
creates *five* list objects before binding the fifth
list object to x. Four of the five objects are
discarded.
Or:
>>> x = range(100) + [2]
creates three list objects and discards two.
How can we make this more efficient?
The implementation overview:
When the Python VM POP()s two objects from the stack
when doing a BINARY_* opcode, the frame owns one
reference to each object. If the left operand object
(second one popped) has a reference count of 1, then
the object is only reachable by the VM in this frame.
Since the VM will DECREF() the object after completing
the binary operation and thus discard it, why not do
the in-place version of the binary operation? This
makes the above example more efficient (by making only
three list objects and two list objects, respectively).
Any questions, mail me or post to python-list, where
the patch and other discussion is present. The patch
posted to python-list is against 2.1b1 release. On Mon
Apr 09, I will create a cvs diff against current tree
and upload here on Sourceforge.
|