This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Inplace optimization for binary ops
Type: Stage:
Components: Interpreter Core Versions:
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: jhylton Nosy List: gvanrossum, jhylton, robin900
Priority: normal Keywords: patch

Created on 2001-04-06 20:06 by robin900, last changed 2022-04-10 16:03 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
cevaldiff.txt robin900, 2001-04-12 01:00 patch to Python/ceval.c (diff -c)
Messages (5)
msg36294 - (view) Author: Robin Thomas (robin900) Date: 2001-04-06 20:06
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.


msg36295 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2001-04-10 21:29
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.
msg36296 - (view) Author: Robin Thomas (robin900) Date: 2001-04-11 15:21
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.

msg36297 - (view) Author: Robin Thomas (robin900) Date: 2001-04-12 01:00
Logged In: YES 
user_id=127529

The performance stats are bad: a loss (on my Solaris Sparc) 
of ~180 pystones/sec. Sigh.

I'm posting the patch anyway, so that if others find it 
useful and wish to revive, it will be here.

msg36298 - (view) Author: Robin Thomas (robin900) Date: 2001-04-23 19:50
Logged In: YES 
user_id=127529

closing patch since it's not relevant to current 
development.
History
Date User Action Args
2022-04-10 16:03:56adminsetgithub: 34294
2001-04-06 20:06:03robin900create