[Patches] [ python-Patches-606098 ] fast dictionary lookup by name

noreply@sourceforge.net noreply@sourceforge.net
Fri, 15 Nov 2002 08:55:28 -0800

Patches item #606098, was opened at 2002-09-07 14:36
You can respond by visiting: 

Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Oren Tirosh (orenti)
>Assigned to: Guido van Rossum (gvanrossum)
Summary: fast dictionary lookup by name

Initial Comment:
This patch speeds up dictionary lookup when the key
is an interned string.

Test results (Guido's tar from patch #597907)

 builtin 2.01
 global 1.57
 local 1.87
 fastlocal 1.02

 builtin 1.78
 global 1.63
 local 1.51
 fastlocal 1.06
Not as impressive as the last patch because this
version doesn't use the inline macro yet.

A dummy/negative entry is now defined as me_key !=
NULL and me_value == NULL. A dummy entry also has
me_hash set to -1 to shave a few more cycles in the

Management of negative entries and the interaction
with table resizing still needs more work. If there
is not enough room for a new negative entry it is
simply ignored.

The bottlneck appears to be the first negative
lookup. It starts with a fast search that fails and
then falls back to a slow search and inserts a
negative entry.  This path is significantly slower
than without the patch. Subsequent lookups will be
much faster but many objects are created where
attributes or methods are looked up just once. 
The solution I am considering is to change
lookdict_string to lookdict_interned.  A dictionary
in this state has only interned string keys so the
fast search is guaranteed to produce the correct
result if the lookup key is also an interned string
with no fallback required.  This should also make it
easier to speed up PyDict_SetItem.


>Comment By: Guido van Rossum (gvanrossum)
Date: 2002-11-15 11:55

Logged In: YES 

Assigned to me because it may relate to patch 597907.

But I have no time to sort through this, and it seems Oren's
priorities lie elsewhere. If someone can help out, please do!


You can respond by visiting: