[pypy-svn] r54594 - in pypy/branch/gc-tweak/pypy/rpython/memory: . gc test

arigo at codespeak.net arigo at codespeak.net
Fri May 9 15:50:30 CEST 2008


Author: arigo
Date: Fri May  9 15:50:28 2008
New Revision: 54594

Modified:
   pypy/branch/gc-tweak/pypy/rpython/memory/gc/generation.py
   pypy/branch/gc-tweak/pypy/rpython/memory/lldict.py
   pypy/branch/gc-tweak/pypy/rpython/memory/support.py
   pypy/branch/gc-tweak/pypy/rpython/memory/test/test_lldict.py
Log:
Revert r54589, which turned out to be a pessimization.
Add comment about why (probably) it was a bad idea.


Modified: pypy/branch/gc-tweak/pypy/rpython/memory/gc/generation.py
==============================================================================
--- pypy/branch/gc-tweak/pypy/rpython/memory/gc/generation.py	(original)
+++ pypy/branch/gc-tweak/pypy/rpython/memory/gc/generation.py	Fri May  9 15:50:28 2008
@@ -468,16 +468,16 @@
             return SemiSpaceGC._compute_id(self, obj)
 
     def update_young_objects_with_id(self):
-        # 'foreach_clear' iterates over the items in the dict and clears
-        # it in the same pass.  It does not shrink the dictionary, which
-        # is appropriate for our use case: the dict will tend to be large
-        # enough for the maximum number of objects with id that exist in
-        # the nursery, and stay at that size for the rest of the execution.
-        self.young_objects_with_id.foreach_clear(self._update_object_id,
-                                                 self.objects_with_id)
+        self.young_objects_with_id.foreach(self._update_object_id,
+                                           self.objects_with_id)
+        self.young_objects_with_id.clear()
+        # NB. the clear() also makes the dictionary shrink back to its
+        # minimal size, which is actually a good idea: a large, mostly-empty
+        # table is bad for the next call to 'foreach'.
 
     def ids_grow_older(self):
-        self.young_objects_with_id.foreach_clear(self._id_grow_older, None)
+        self.young_objects_with_id.foreach(self._id_grow_older, None)
+        self.young_objects_with_id.clear()
 
     def _id_grow_older(self, obj, id, ignored):
         self.objects_with_id.setitem(obj, id)

Modified: pypy/branch/gc-tweak/pypy/rpython/memory/lldict.py
==============================================================================
--- pypy/branch/gc-tweak/pypy/rpython/memory/lldict.py	(original)
+++ pypy/branch/gc-tweak/pypy/rpython/memory/lldict.py	Fri May  9 15:50:28 2008
@@ -69,19 +69,6 @@
         i -= 1
 dict_foreach._annspecialcase_ = 'specialize:arg(1)'
 
-def dict_foreach_clear(d, callback, arg):
-    entries = d.entries
-    i = len(entries) - 1
-    while i >= 0:
-        if dict_entry_valid(entries, i):
-            key = entries[i].key
-            entries[i].key = llmemory.NULL
-            callback(key, entries[i].value, arg)
-        i -= 1
-    d.num_items = 0
-    d.num_pristine_entries = len(entries)
-dict_foreach_clear._annspecialcase_ = 'specialize:arg(1)'
-
 ENTRY = lltype.Struct('ENTRY', ('key', llmemory.Address),
                                ('value', llmemory.Address))
 ENTRIES = lltype.Array(ENTRY,
@@ -104,8 +91,8 @@
                          'get': dict_get,
                          'add': dict_add,
                          'insertclean': dict_insertclean,
+                         'clear': rdict.ll_clear,
                          'foreach': dict_foreach,
-                         'foreach_clear': dict_foreach_clear,
                          'keyhash': dict_keyhash,
                          'keyeq': None,
                      })

Modified: pypy/branch/gc-tweak/pypy/rpython/memory/support.py
==============================================================================
--- pypy/branch/gc-tweak/pypy/rpython/memory/support.py	(original)
+++ pypy/branch/gc-tweak/pypy/rpython/memory/support.py	Fri May  9 15:50:28 2008
@@ -257,8 +257,7 @@
     def add(self, keyaddr):
         self.setitem(keyaddr, llmemory.NULL)
 
-    def foreach_clear(self, callback, arg):
-        self.foreach(callback, arg)
+    def clear(self):
         self.data.clear()
 
     def foreach(self, callback, arg):

Modified: pypy/branch/gc-tweak/pypy/rpython/memory/test/test_lldict.py
==============================================================================
--- pypy/branch/gc-tweak/pypy/rpython/memory/test/test_lldict.py	(original)
+++ pypy/branch/gc-tweak/pypy/rpython/memory/test/test_lldict.py	Fri May  9 15:50:28 2008
@@ -60,18 +60,12 @@
         d2.delete()
         assert lldict.alloc_count == 0
 
-    def test_foreach_clear(self):
+    def test_clear(self):
         d = lldict.newdict()
         d.setitem(intaddr(41), intaddr(42))
-        result = []
-        d.foreach_clear(lambda key, value, arg: result.append((key,value,arg)),
-                        "hello world")
+        d.clear()
         assert d.length() == 0
         assert not d.contains(intaddr(41))
-        assert len(result) == 1
-        assert result[0][0].intval == 41
-        assert result[0][1].intval == 42
-        assert result[0][2] == "hello world"
         d.delete()
         assert lldict.alloc_count == 0
 



More information about the Pypy-commit mailing list