[Patches] [ python-Patches-711722 ] Cache lookup of __builtins__
SourceForge.net
noreply@sourceforge.net
Fri, 28 Mar 2003 22:47:47 -0800
Patches item #711722, was opened at 2003-03-29 01:47
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=711722&group_id=5470
Category: Core (C code)
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Raymond Hettinger (rhettinger)
Assigned to: Nobody/Anonymous (nobody)
Summary: Cache lookup of __builtins__
Initial Comment:
Rather than perform a bytecode optimization of
LOAD_GLOBALS, takes an alternative approach of
caching the lookup of builtins.
To be safe, it checks the cache only after trying a
lookup in globals(). I can think of only one way to
break this approach: run the function accessing a
builtin, then poke a new value into the builtins
module, and then re-run the function:
def f(x):
return oct(x)
print f(20)
__builtins__.oct = hex
print f(20) # doesn't notice new def of oct()
The gives about a 2% speed-up to average programs,
0% to programs that don't use builtins, and higher
percentages to those with heavier use of builtins. The
speedup is limited by 1) having to still check globals
and 2) the relative insignificance of builtin access time
in most programs. Still, it pretty much solves the
problem of access time for builtins.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=711722&group_id=5470