8000 Restore the data block size to 62. · python/cpython@7757820 · GitHub
[go: up one dir, main page]

Skip to content
< 10000 /react-partial>

Commit 7757820

Browse files
committed
Restore the data block size to 62.
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".
1 parent 1f1d0a5 commit 7757820

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

Lib/test/test_deque.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ class C(object):
536536

537537
@support.cpython_only
538538
def test_sizeof(self):
539-
BLOCKLEN = 64
539+
BLOCKLEN = 62
540540
basesize = support.calcobjsize('2P4nlP')
541541
blocksize = struct.calcsize('2P%dP' % BLOCKLEN)
542542
self.assertEqual(object.__sizeof__(deque()), basesize)

Modules/_collectionsmodule.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
1010
/* The block length may be set to any number over 1. Larger numbers
1111
* reduce the number of calls to the memory allocator, give faster
1212
* indexing and rotation, and reduce the link::data overhead ratio.
13-
* If the block length is a power-of-two, we also get faster
14-
* division/modulo computations during indexing.
13+
*
14+
* Ideally, the block length will be set to two less than some
15+
* multiple of the cache-line length (so that the full block
16+
* including the leftlink and rightlink will fit neatly into
17+
* cache lines).
1518
*/
1619

17-
#define BLOCKLEN 64
20+
#define BLOCKLEN 62
1821
#define CENTER ((BLOCKLEN - 1) / 2)
1922

2023
/* A `dequeobject` is composed of a doubly-linked list of `block` nodes.

0 commit comments

Comments
 (0)
0