]> granicus.if.org Git - python/commitdiff
Bump the blocksize up from 62 to 64 to speed up the modulo calculation.
authorRaymond Hettinger <python@rcn.com>
Fri, 27 Feb 2015 07:21:29 +0000 (23:21 -0800)
committerRaymond Hettinger <python@rcn.com>
Fri, 27 Feb 2015 07:21:29 +0000 (23:21 -0800)
Remove the old comment suggesting that it was desireable to have
blocksize+2 as a multiple of the cache line length.  That would
have made sense only if the block structure start point was always
aligned to a cache line boundary.  However, the memory allocations
are 16 byte aligned, so we don't really have control over whether
the struct spills across cache line boundaries.

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

index e336e5a38489affeff21a376e896491e9180977c..0eebbff84127a2666aa8318ec99646ba92b8b5ff 100644 (file)
@@ -542,7 +542,7 @@ class TestBasic(unittest.TestCase):
 
     @support.cpython_only
     def test_sizeof(self):
-        BLOCKLEN = 62
+        BLOCKLEN = 64
         basesize = support.calcobjsize('2P4nlP')
         blocksize = struct.calcsize('2P%dP' % BLOCKLEN)
         self.assertEqual(object.__sizeof__(deque()), basesize)
index d3b0287abdf43743aa7f0e97e555791344936307..0df35d959c832a8a68e33408918ad1d9a1b76f16 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 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).
+ * Making the block length a power of two speeds-up the modulo
+ * calculation in deque_item().
  */
 
-#define BLOCKLEN 62
+#define BLOCKLEN 64
 #define CENTER ((BLOCKLEN - 1) / 2)
 
 /* A `dequeobject` is composed of a doubly-linked list of `block` nodes.