Skip to content

Commit 318c3aa

Browse files
committed
2x speedup from __builtin_prefetch
1 parent 41b2b38 commit 318c3aa

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lazysorted.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242
#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
4343
#endif
4444

45+
/* Macros to support different compilers */
46+
#if !(defined(__GNUC__) || defined(__clang__))
47+
#define __builtin_prefetch(x)
48+
#endif
49+
4550
/* Definitions and functions for the binary search tree of pivot points.
4651
* The BST implementation is a Treap, selected because of its general speed,
4752
* especially when inserting and removing elements, which happens a lot in this
@@ -709,6 +714,7 @@ partition(LSObject *ls, Py_ssize_t left, Py_ssize_t right)
709714

710715
Py_ssize_t i;
711716
for (i = left + 1; i < right; i++) {
717+
__builtin_prefetch(ob_item[i+3]);
712718
IFLT(ob_item[i], pivot) {
713719
last_less++;
714720
SWAP(i, last_less);

0 commit comments

Comments
 (0)