[pypy-commit] pypy all_ordered_dicts: Trying to overallocate dicts a little bit more eagerly
arigo
noreply at buildbot.pypy.org
Sat Jan 17 18:03:16 CET 2015
Author: Armin Rigo <arigo at tunes.org>
Branch: all_ordered_dicts
Changeset: r75413:4a6947ecc8fe
Date: 2015-01-17 18:03 +0100
http://bitbucket.org/pypy/pypy/changeset/4a6947ecc8fe/
Log: Trying to overallocate dicts a little bit more eagerly
diff --git a/rpython/rtyper/lltypesystem/rordereddict.py b/rpython/rtyper/lltypesystem/rordereddict.py
--- a/rpython/rtyper/lltypesystem/rordereddict.py
+++ b/rpython/rtyper/lltypesystem/rordereddict.py
@@ -617,18 +617,13 @@
def _overallocate_entries_len(baselen):
# This over-allocates proportional to the list size, making room
- # for additional growth. The over-allocation is mild, but is
- # enough to give linear-time amortized behavior over a long
- # sequence of appends() in the presence of a poorly-performing
- # system malloc().
- # The growth pattern is: 0, 4, 8, 16, 25, 35, 46, 58, 72, 88, ...
- newsize = baselen + 1
- if newsize < 9:
- some = 3
- else:
- some = 6
- some += newsize >> 3
- return newsize + some
+ # for additional growth. This over-allocates slightly more eagerly
+ # than with regular lists. The idea is that there are many more
+ # lists than dicts around in PyPy, and dicts of 5 to 8 items are
+ # not that rare (so a single jump from 0 to 8 is a good idea).
+ # The growth pattern is: 0, 8, 17, 27, 38, 50, 64, 80, 98, ...
+ newsize = baselen + (baselen >> 3)
+ return newsize + 8
@jit.look_inside_iff(lambda d: jit.isvirtual(d))
def ll_dict_grow(d):
@@ -947,7 +942,9 @@
#
# Irregular operations.
-DICT_INITSIZE = 8
+# Start the hashtable size at 16 rather than 8, as with rdict.py, because
+# it is only an array of bytes
+DICT_INITSIZE = 16
@specialize.memo()
diff --git a/rpython/rtyper/test/test_rordereddict.py b/rpython/rtyper/test/test_rordereddict.py
--- a/rpython/rtyper/test/test_rordereddict.py
+++ b/rpython/rtyper/test/test_rordereddict.py
@@ -115,11 +115,18 @@
rordereddict.ll_dict_setitem(ll_d, llstr("b"), 2)
rordereddict.ll_dict_setitem(ll_d, llstr("c"), 3)
rordereddict.ll_dict_setitem(ll_d, llstr("d"), 4)
- assert len(get_indexes(ll_d)) == 8
rordereddict.ll_dict_setitem(ll_d, llstr("e"), 5)
rordereddict.ll_dict_setitem(ll_d, llstr("f"), 6)
- assert len(get_indexes(ll_d)) == 32
- for item in ['a', 'b', 'c', 'd', 'e', 'f']:
+ rordereddict.ll_dict_setitem(ll_d, llstr("g"), 7)
+ rordereddict.ll_dict_setitem(ll_d, llstr("h"), 8)
+ rordereddict.ll_dict_setitem(ll_d, llstr("i"), 9)
+ rordereddict.ll_dict_setitem(ll_d, llstr("j"), 10)
+ assert len(get_indexes(ll_d)) == 16
+ rordereddict.ll_dict_setitem(ll_d, llstr("k"), 11)
+ rordereddict.ll_dict_setitem(ll_d, llstr("l"), 12)
+ rordereddict.ll_dict_setitem(ll_d, llstr("m"), 13)
+ assert len(get_indexes(ll_d)) == 64
+ for item in 'abcdefghijklm':
assert rordereddict.ll_dict_getitem(ll_d, llstr(item)) == ord(item) - ord('a') + 1
def test_dict_grow_cleanup(self):
More information about the pypy-commit
mailing list