[Patches] [ python-Patches-414391 ] Inplace optimization for binary ops

noreply@sourceforge.net noreply@sourceforge.net
Fri, 06 Apr 2001 13:06:04 -0700


Patches item #414391, was updated on 2001-04-06 13:06
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=414391&group_id=5470

Category: core (C code)
Group: None
Status: Open
Priority: 5
Submitted By: Robin Thomas (robin900)
Assigned to: Nobody/Anonymous (nobody)
Summary: Inplace optimization for binary ops

Initial Comment:
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.




----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=414391&group_id=5470