Commit Graph

74 Commits

Author SHA1 Message Date
Raymond Hettinger
77578204d6 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".
2013-07-28 02:39:49 -07:00
Raymond Hettinger
3223dd5c22 Assertions key off NDEBUG 2013-07-26 23:14:22 -07:00
Raymond Hettinger
b97cc49c3a Minor code simplification by eliminating an unnecessary temporary variable. 2013-07-21 01:51:07 -07:00
Raymond Hettinger
90dea4ce43 Tweak the deque struct by moving the least used fields (maxlen and weakref) to the end. 2013-07-13 22:30:25 -07:00
Raymond Hettinger
840533bf1c Use a do-while loop in the inner loop for rotate (m is always greater than zero). 2013-07-13 17:03:58 -07:00
Raymond Hettinger
3959af9b2a Move the freeblock() call outside the main loop to speed-up and simplify the block re-use logic. 2013-07-13 02:34:08 -07:00
Raymond Hettinger
d9c116ca40 Add a spacing saving heuristic to deque's extend methods 2013-07-09 00:13:21 -07:00
Raymond Hettinger
b385529ddf Fix #ifdef 2013-07-07 02:07:23 -10:00
Raymond Hettinger
82df925451 Use macros for marking and checking endpoints in the doubly-linked list of blocks.
* Add comment explaining the endpoint checks
* Only do the checks in a debug build
* Simplify newblock() to only require a length argument
  and leave the link updates to the calling code.
* Also add comment for the freelisting logic.
2013-07-07 01:43:42 -10:00
Raymond Hettinger
f3a67b7e57 Improve variable names in deque_count() 2013-07-06 17:49:06 -10:00
Raymond Hettinger
df715ba54d Apply the PyObject_VAR_HEAD and Py_SIZE macros
to be consistent with practices in other modules.
2013-07-06 13:01:13 -10:00
Raymond Hettinger
5bfa8671bc Refactor deque_traverse().
Hoist conditional expression out of the loop.
Use rightblock as the guard instead of checking for NULL.
2013-07-06 11:58:09 -10:00
Raymond Hettinger
98054b4c1b Remove unnecessary branches from count() and reverse(). 2013-07-06 09:07:06 -10:00
Raymond Hettinger
de68e0cf0e Speed-up deque indexing by changing the deque block length to a power of two.
The division and modulo calculation in deque_item() can be compiled
to fast bitwise operations when the BLOCKLEN is a power of two.

Timing before:

 ~/cpython $ py -m timeit -r7 -s 'from collections import deque' -s 'd=deque(range(10))' 'd[5]'
10000000 loops, best of 7: 0.0627 usec per loop

Timing after:

~/cpython $ py -m timeit -r7 -s 'from collections import deque' -s 'd=deque(range(10))' 'd[5]'
10000000 loops, best of 7: 0.0581 usec per loop
2013-07-05 18:05:29 -10:00
Raymond Hettinger
20b0f87e1d Misc improvements to collections.deque()
* Clarified comment on the impact of BLOCKLEN on deque_index
  (with a power-of-two, the division and modulo
   computations are done with a right-shift and bitwise-and).

* Clarified comment on the overflow check to note that
  it is general and not just applicable the 64-bit builds.

* In deque._rotate(), the "deque->" indirections are
  factored-out of the loop (loop invariant code motion),
  leaving the code cleaner looking and slightly faster.

* In deque._rotate(), replaced the memcpy() with an
  equivalent loop.  That saved the memcpy setup time
  and allowed the pointers to move in their natural
  leftward and rightward directions.

See comparative timings at:  http://pastebin.com/p0RJnT5N
2013-06-23 15:44:33 -07:00
Raymond Hettinger
59cf23ab07 Minor tweaks to varnames, declarations, and comments. 2013-02-07 00:57:19 -05:00
Raymond Hettinger
1f0044c473 Minor variable access clean-ups for deque.rotate(). 2013-02-05 01:30:46 -05:00
Raymond Hettinger
a4409c18eb Minor edits: Tighten-up the halflen logic and touch-up the assertions and comments. 2013-02-04 00:08:12 -05:00
Raymond Hettinger
3a9ae7fd98 Issue 16398: One more assertion for good measure. 2013-02-02 12:26:37 -08:00
Raymond Hettinger
231ee4dc9d Issue 16398: Add assertions to show why memcmp is safe. 2013-02-02 11:24:43 -08:00
Raymond Hettinger
21777acd68 Issue 16398: Use memcpy() in deque.rotate(). 2013-02-02 09:56:08 -08:00
Benjamin Peterson
fa3965ab76 merge 3.3 2013-01-12 21:22:33 -05:00
Benjamin Peterson
0e5c48a917 make deque_clear void, since it's infallible 2013-01-12 21:22:18 -05:00
Raymond Hettinger
464d89b3ce Issue #16398: Optimize deque.rotate() 2013-01-11 22:29:50 -08:00
Andrew Svetlov
796c443f3d Merge: fix docstring for deque ctor to mark iterable parameter optional 2012-10-31 11:51:13 +02:00