[Patches] [ python-Patches-597907 ] Oren Tirosh's fastnames patch

noreply@sourceforge.net noreply@sourceforge.net
Mon, 23 Sep 2002 09:35:35 -0700


Patches item #597907, was opened at 2002-08-20 15:20
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=597907&group_id=5470

Category: Core (C code)
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Guido van Rossum (gvanrossum)
Assigned to: Guido van Rossum (gvanrossum)
Summary: Oren Tirosh's fastnames patch

Initial Comment:
Oren Tirosh had a nice patch to *really* speed up
global/builtin name lookup. I'm adding it here because
I don't want to lose this idea.

His code and some comments are here:

http://www.tothink.com/python/fastnames/

I'm uploading a new version of this patch relative to
current CVS.

I'm still considering whether to do this; I measure at
best a 1% speedup for pystone.

For a modified version of Oren's benchmark (modified to
use a function instead of a class for 'builtin' and
'global', so that these tests use LOAD_GLOBAL rather
than LOAD_NAME, I get these test results (best of 3):

   builtin 1.38
    global 1.54
     local 1.28
 fastlocal 0.90

Python 2.3 without his patch (but with my speedup hacks
in LOAD_GLOBAL):

   builtin 1.80
    global 1.52
     local 1.77
 fastlocal 0.91

Python 2.2 (from the 2.2 branch, which is newer than
the 2.2.1 release but doesn't have any speedups) did this:

   builtin 2.28
    global 1.86
     local 1.80
 fastlocal 1.10

I don't care about the speedup for the 'local' case,
since this uses the LOAD_NAME opcode which is only used
inside class definitions; the 'builtin' and 'global'
cases are interesting. It looks like Oren's patch gives
us a nice speedup for looking up a built-in name from a
function. I have to think about why looking up a global
from a function is slower though...

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

>Comment By: Guido van Rossum (gvanrossum)
Date: 2002-09-23 12:35

Message:
Logged In: YES 
user_id=6380

Oren, any chance that you'll submit a new version of this?

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

Comment By: Oren Tirosh (orenti)
Date: 2002-09-03 16:22

Message:
Logged In: YES 
user_id=562624

> I'm still considering whether to do this; I measure at
> best a 1% speedup for pystone.

No surprising considering the fact that pystone is dominated
by fastlocals (IIRC it was something like 99.7% according to
my instrumented version).

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

Comment By: Guido van Rossum (gvanrossum)
Date: 2002-09-03 14:29

Message:
Logged In: YES 
user_id=6380

OK. I'm holding my breath! :-)

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

Comment By: Oren Tirosh (orenti)
Date: 2002-09-02 15:59

Message:
Logged In: YES 
user_id=562624

I'm working on an improved version. Stay tuned!


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

Comment By: Guido van Rossum (gvanrossum)
Date: 2002-08-20 15:31

Message:
Logged In: YES 
user_id=6380

Tim explained why the 'globals' case is faster than the
'builtins' case. I used 'x' as the global to look up rather
than 'hex', and it so happens that the last three bits of
hash('x') and hash('MANY') are the same -- MANY is an
identifier I insert in the globals.  I'll attach the test
suite I used (with 'hex' instead of 'x'). Now I get these times:

   builtin 1.39
    global 1.28
     local 1.29
 fastlocal 0.91


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

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