[New-bugs-announce] [issue10401] Globals / builtins cache

Antoine Pitrou report at bugs.python.org
Fri Nov 12 22:24:40 CET 2010

New submission from Antoine Pitrou <pitrou at free.fr>:

Here is the Nth patch for a globals/builtins cache. As other caches at the same kind, it shows very small to no gain on non-micro benchmarks, showing that contrary to popular belief, globals/builtins lookup are not a major roadblock in today's Python performance.

However, this patch could be useful in combination with other optimizations such as issue10399.  Indeed, using the globals/builtins version id, it is easy and very cheap to detect whether the function pointed to by a global name has changed or not.

As for micro-benchmarks, they show that there is indeed a good improvement on builtins lookups:

$ ./python -m timeit "x=len;x=len;x=len;x=len;x=len;x=len;x=len;x=len;x=len;x=len;"
-> without patch:
1000000 loops, best of 3: 0.282 usec per loop
-> with patch:
10000000 loops, best of 3: 0.183 usec per loop

components: Interpreter Core
files: globcache5.patch
keywords: patch
messages: 121081
nosy: alex, belopolsky, benjamin.peterson, dmalcolm, jhylton, nnorwitz, pitrou, rhettinger, sdahlbac, thomas.lee, titanstar
priority: low
severity: normal
stage: patch review
status: open
title: Globals / builtins cache
type: performance
versions: Python 3.3
Added file: http://bugs.python.org/file19590/globcache5.patch

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list