[Patches] [ python-Patches-414391 ] Inplace optimization for binary ops
noreply@sourceforge.net
noreply@sourceforge.net
Wed, 11 Apr 2001 08:21:10 -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.
----------------------------------------------------------------------
>Comment By: Robin Thomas (robin900)
Date: 2001-04-11 08:21
Message:
Logged In: YES
user_id=127529
Yes, I'll upload; I never wanted to to go hunting for the
patch! :)
Some colleagues and I have gathered performance stats on
the patch. List concat/repeat is 15-25% faster, but ops on
built-in numerics are 1-2% slower. Using Python "make test"
to measure the distribution of ops/types, it's almost a
wash: ops on built-in numerics are about 10 times more
common than list concat/repeat.
However, we don't want this patch to be list-specific; the
original need was for a general hook so that extension
types and user-defined classes could take advantage of the
in-place optimization without doing fancy dancing in their
own code.
Thus, the patch will include a README with our performance
and survey findings, and we'll leave the issue open for
debate.
Expect a patch upload today or tomorrow.
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2001-04-10 14:29
Message:
Logged In: YES
user_id=6380
Sorry, I don't have the resources to search c.l.py. Can you
please upload your patch here? The file uploads should work
fine if you check the checkbox above the Browse button.
This won't go into 2.1, obviously, so a patch against 2.1
when it is released (expected 4/16/01) would work too.
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=414391&group_id=5470