[Python-Dev] [ python-Patches-876206 ] scary frame speed hacks

Armin Rigo arigo at tunes.org
Mon Mar 1 11:12:15 EST 2004


We are about to apply a patch that both speeds up frame allocation and make it 
simpler by removing the frame freelist (patch #876206).

The drawback is that recursive functions would be slower now.  The two 
alternatives that we have are thus:

(1) Ignore the recursive function problem and apply the patch.

def f(n, m):
    if n > 0 and m > 0:
        return f(n-1, m) + f(n, m-1)
        return 1
f(11, 11)

Takes 3.26s instead of just 2.64s.  This is a major speed hit (20%).  On the
other hand, recursive functions are not so common in Python, and the patch
simplifies the C source interestingly.

(2) Don't remove the frame freelist but combine it with the new patch.

This would give the best of both worlds performance-wise, but the frame
allocation code becomes convoluted.  It would amount to add a third way to
allocate a frame, and all three ways give a frame with different guaranteed
invariants (i.e. different sets of fields that we know to be already correct
and thus don't have to initialize).

The question is whether (1) or (2) is better.


More information about the Python-Dev mailing list