[pypy-commit] pypy rpython-hash: Fix test_memoryerror by using the most tight estimate in

arigo pypy.commits at gmail.com
Thu Jan 26 08:55:20 EST 2017


Author: Armin Rigo <arigo at tunes.org>
Branch: rpython-hash
Changeset: r89787:9a1928019d6b
Date: 2017-01-26 14:54 +0100
http://bitbucket.org/pypy/pypy/changeset/9a1928019d6b/

Log:	Fix test_memoryerror by using the most tight estimate in
	ll_dict_create_index. This value should have the same guarantee in
	real program: if we get out of memory inserting a new item, then the
	recreated index is still of the smaller size instead of being bigger
	(and then likely not fitting in memory either)

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
@@ -879,9 +879,15 @@
     if d.num_live_items == 0:
         new_size = DICT_INITSIZE     # fast path
     else:
-        new_estimate = d.num_live_items  * 2
+        # Use a more conservative estimate than _ll_dict_resize_to() here.
+        # This function is called when initially creating the index (so,
+        # for prebuilt dicts, the chance is that it will never grow);
+        # after we got a MemoryError; and when throwing the index away
+        # because of heavy shrinking of the dict.  The minimum value
+        # here is such that 'new_estimate * 2 - num_live_items * 3 > 0'.
+        new_estimate = (d.num_live_items * 3) // 2 + 1
         new_size = DICT_INITSIZE
-        while new_size <= new_estimate:
+        while new_size < new_estimate:
             new_size *= 2
     ll_dict_reindex(d, new_size)
 


More information about the pypy-commit mailing list