[Python-Dev] New opcode to simplifiy/speedup list comprehensions

Brett C. bac at OCF.Berkeley.EDU
Sat Mar 6 15:47:53 EST 2004


Raymond Hettinger wrote:

> If there are no objections, I would like to add an opcode for calling
> PyList_Append().  This simplifies the generated code for list
> comprehensions and reduces the overhead on each pass, improving the
> timings by about 35% on [i for i in itertools.repeat(None, 500)].
> 
> The patch is amazingly brief and clear:
> 	www.python.org/sf/910929
> 

Ah, nuts!  That was going to be part of my thesis!  =)  I was going to 
along the lines of "Type-specific Opcodes for Python Based on Static 
Type Inferencing of Local Variables".  At this rate the the first four 
words won't be needed.  =)

Joking aside, I am +1 since I was planning on adding that myself as long 
as my thesis pans out and actually is a gain.

Oh, and beware the evil cache monkey and his notorious way of making the 
eval loop not fit in the CPU cache when a single thing is added to it 
(or at least I remember a comment along those lines last time people 
tried fiddling with the eval loop).

-Brett



More information about the Python-Dev mailing list