]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Restore the data block size to 62.
authorRaymond Hettinger <python@rcn.com>
Sun, 28 Jul 2013 09:34:42 +0000 (02:34 -0700)
committerRaymond Hettinger <python@rcn.com>
Sun, 28 Jul 2013 09:34:42 +0000 (02:34 -0700)
The former block size traded away good fit within cache lines in
order to gain faster division in deque_item().  However, compilers
are getting smarter and can now replace the slow division operation
with a fast integer multiply and right shift.  Accordingly, it makes
sense to go back to a size that lets blocks neatly fill entire
cache-lines.

GCC-4.8 and CLANG 4.0 both compute "x // 62" with something
roughly equivalent to "x * 9520900167075897609 >> 69".

Lib/test/test_deque.py
Modules/_collectionsmodule.c

index 98b203edb60a730f33ea4e2e405ae0137553d2ba..595a0c4a35cace415f66468eb046664d63c2ec63 100644 (file)
@@ -522,7 +522,7 @@ class TestBasic(unittest.TestCase):
 
     @test_support.cpython_only
     def test_sizeof(self):
-        BLOCKLEN = 64
+        BLOCKLEN = 62
         basesize = test_support.calcobjsize('2P4PlP')
         blocksize = struct.calcsize('2P%dP' % BLOCKLEN)
         self.assertEqual(object.__sizeof__(deque()), basesize)
index dc31cbc9b0e744f583b2041e2def27f4160acb4e..26d878344e1860822a73eed846c4137c5651fe14 100644 (file)
 /* The block length may be set to any number over 1.  Larger numbers
  * reduce the number of calls to the memory allocator, give faster
  * indexing and rotation, and reduce the link::data overhead ratio.
- * Ideally, the block length should be a power-of-two for faster
- * division/modulo computations during indexing.
+ *
+ * Ideally, the block length will be set to two less than some
+ * multiple of the cache-line length (so that the full block
+ * including the leftlink and rightlink will fit neatly into
+ * cache lines).
  */
 
-#define BLOCKLEN 64
+#define BLOCKLEN 62
 #define CENTER ((BLOCKLEN - 1) / 2)
 
 /* A `dequeobject` is composed of a doubly-linked list of `block` nodes.