This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ntoronto
Recipients ntoronto
Date 2007-11-29.09:43:47
SpamBayes Score 0.016687043
Marked as misclassified No
Message-id <1196329437.66.0.0945045609125.issue1518@psf.upfronthosting.co.za>
In-reply-to
Content
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.
Files
File name Uploaded
fastglobals.patch.txt ntoronto, 2007-11-29.09:43:47
History
Date User Action Args
2007-11-29 09:43:58ntorontosetspambayes_score: 0.016687 -> 0.016687043
recipients: + ntoronto
2007-11-29 09:43:57ntorontosetspambayes_score: 0.016687 -> 0.016687
messageid: <1196329437.66.0.0945045609125.issue1518@psf.upfronthosting.co.za>
2007-11-29 09:43:57ntorontolinkissue1518 messages
2007-11-29 09:43:55ntorontocreate