Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
9d5c4430
Commit
9d5c4430
authored
Mar 15, 2004
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix typos and add some elaborations
parent
cd1e8a94
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
4 deletions
+9
-4
Objects/dictnotes.txt
Objects/dictnotes.txt
+9
-4
No files found.
Objects/dictnotes.txt
View file @
9d5c4430
...
...
@@ -94,7 +94,7 @@ Tunable Dictionary Parameters
* Growth rate upon hitting maximum load. Currently set to *2.
Raising this to *4 results in half the number of resizes,
less effort to resize, better sparseness for some (but not
all dict sizes), and potentially double memory consumption
all dict sizes), and potentially double
s
memory consumption
depending on the size of the dictionary. Setting to *4
eliminates every other resize step.
...
...
@@ -112,6 +112,8 @@ iteration and key listing. Those methods loop over every potential
entry. Doubling the size of dictionary results in twice as many
non-overlapping memory accesses for keys(), items(), values(),
__iter__(), iterkeys(), iteritems(), itervalues(), and update().
Also, every dictionary iterates at least twice, once for the memset()
when it is created and once by dealloc().
Results of Cache Locality Experiments
...
...
@@ -191,6 +193,8 @@ sizes and access patterns, the user may be able to provide useful hints.
is not at a premium, the user may benefit from setting the maximum load
ratio at 5% or 10% instead of the usual 66.7%. This will sharply
curtail the number of collisions but will increase iteration time.
The builtin namespace is a prime example of a dictionary that can
benefit from being highly sparse.
2) Dictionary creation time can be shortened in cases where the ultimate
size of the dictionary is known in advance. The dictionary can be
...
...
@@ -199,7 +203,7 @@ sizes and access patterns, the user may be able to provide useful hints.
more quickly because the first half of the keys will be inserted into
a more sparse environment than before. The preconditions for this
strategy arise whenever a dictionary is created from a key or item
sequence and the number of
unique
keys is known.
sequence and the number of
*unique*
keys is known.
3) If the key space is large and the access pattern is known to be random,
then search strategies exploiting cache locality can be fruitful.
...
...
@@ -228,11 +232,12 @@ The dictionary can be immediately rebuilt (eliminating dummy entries),
resized (to an appropriate level of sparseness), and the keys can be
jostled (to minimize collisions). The lookdict() routine can then
eliminate the test for dummy entries (saving about 1/4 of the time
spen
d
in the collision resolution loop).
spen
t
in the collision resolution loop).
An additional possibility is to insert links into the empty spaces
so that dictionary iteration can proceed in len(d) steps instead of
(mp->mask + 1) steps.
(mp->mask + 1) steps. Alternatively, a separate tuple of keys can be
kept just for iteration.
Caching Lookups
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment