[New-bugs-announce] [issue1518] Fast globals/builtins access (patch)

Neil Toronto report at bugs.python.org
Thu Nov 29 10:43:57 CET 2007


New submission from Neil Toronto:

I've attached a patch that reduces LOAD_GLOBAL access time by 19% for 
globals and 45% for builtins. In my tests, that's barely slower than 
LOAD_FAST in both cases.

The approach is to cache pointers to dictionary entries rather than 
caching dictionary values as is usually suggested. Dictionaries keep a 
64-bit "version" internally that is incremented whenever at least one 
entry pointer would become invalid. PyFastGlobalsObject is a 
dictionary adapter, allowing quick access to it using an index instead 
of a key object. It ensures that its entry pointers are always valid 
(by comparing a stored version number against the dictionary's) before 
retrieving values from them.

A script of microbenchmarks, fastglobals_test.py, is included in the 
patch. My dual-core Intel T2300 1.66GHz on Ubuntu 7.04 (compiled 
with -DNDEBUG -g -O3), gets the following results:

Test                     2.6a0 trunk  2.6a0 fastglobals    % time
----                     -----------  -----------------  ----------
Dict ins/del    (100000)    41.27              41.59        1.01
Dict get        (100000)    21.37              21.35        1.00
Dict set        (100000)    21.36              21.33        1.00
Local get      (1000000)    15.64              15.60        1.00
Local set      (1000000)    16.83              16.94        1.01
Global get     (1000000)    21.09              17.04        0.81*
Global set     (1000000)    34.15              22.80        0.67*
Builtin get    (1000000)    30.99              17.04        0.55*
Function call   (100000)    32.87              33.00        1.00
Listcomp        (100000)    28.65              25.17        0.88*
Pystone 1.1     (500000)    12.46              11.68        0.94*
PYBENCH 2.0                  9.10               9.05        0.99
(* = probably significant)

All regressions that aren't skipped pass except test_gc. I've probably 
got a refcount issue or unbreakable cycle somewhere.

----------
components: Interpreter Core
files: fastglobals.patch.txt
messages: 57927
nosy: ntoronto
severity: normal
status: open
title: Fast globals/builtins access (patch)
type: rfe
versions: Python 2.6
Added file: http://bugs.python.org/file8821/fastglobals.patch.txt

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1518>
__________________________________
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: fastglobals.patch.txt
Url: http://mail.python.org/pipermail/new-bugs-announce/attachments/20071129/41d6298e/attachment-0001.txt 


More information about the New-bugs-announce mailing list