mdbx: the radix-sort threshold reduced to 333.

Change-Id: Ic69b6c3740f71997cd014a82fb32a8202ddb65e0
This commit is contained in:
Leonid Yuriev 2021-04-20 22:14:13 +03:00
parent eabb29d9c4
commit c2d8c35daa
2 changed files with 6 additions and 5 deletions

View File

@ -3017,8 +3017,8 @@ RADIXSORT_IMPL(pgno, pgno_t, MDBX_PNL_EXTRACT_KEY,
SORT_IMPL(pgno_sort, false, pgno_t, MDBX_PNL_ORDERED) SORT_IMPL(pgno_sort, false, pgno_t, MDBX_PNL_ORDERED)
static __hot void mdbx_pnl_sort(MDBX_PNL pnl) { static __hot void mdbx_pnl_sort(MDBX_PNL pnl) {
if (likely(MDBX_PNL_SIZE(pnl) < MDBX_PNL_RADIXSORT_THRESHOLD) || if (likely(MDBX_PNL_SIZE(pnl) < MDBX_RADIXSORT_THRESHOLD) ||
!pgno_radixsort(&MDBX_PNL_FIRST(pnl), MDBX_PNL_SIZE(pnl))) unlikely(!pgno_radixsort(&MDBX_PNL_FIRST(pnl), MDBX_PNL_SIZE(pnl))))
pgno_sort(MDBX_PNL_BEGIN(pnl), MDBX_PNL_END(pnl)); pgno_sort(MDBX_PNL_BEGIN(pnl), MDBX_PNL_END(pnl));
assert(mdbx_pnl_check(pnl, MAX_PAGENO + 1)); assert(mdbx_pnl_check(pnl, MAX_PAGENO + 1));
} }
@ -3280,8 +3280,8 @@ SORT_IMPL(dp_sort, false, MDBX_dp, DP_SORT_CMP)
__hot static MDBX_dpl *mdbx_dpl_sort_slowpath(MDBX_dpl *dl) { __hot static MDBX_dpl *mdbx_dpl_sort_slowpath(MDBX_dpl *dl) {
assert(dl->items[0].pgno == 0 && dl->items[dl->length + 1].pgno == P_INVALID); assert(dl->items[0].pgno == 0 && dl->items[dl->length + 1].pgno == P_INVALID);
const unsigned unsorted = dl->length - dl->sorted; const unsigned unsorted = dl->length - dl->sorted;
if (likely(unsorted < MDBX_PNL_RADIXSORT_THRESHOLD) || if (likely(unsorted < MDBX_RADIXSORT_THRESHOLD) ||
!dpl_radixsort(dl->items + 1, dl->length)) { unlikely(!dpl_radixsort(dl->items + 1, dl->length))) {
if (dl->sorted > unsorted / 4 + 4 && if (dl->sorted > unsorted / 4 + 4 &&
(MDBX_DPL_PREALLOC_FOR_RADIXSORT || (MDBX_DPL_PREALLOC_FOR_RADIXSORT ||
dl->length + unsorted < dl->detent + MDBX_DPL_GAP_FOR_MERGESORT)) { dl->length + unsorted < dl->detent + MDBX_DPL_GAP_FOR_MERGESORT)) {

View File

@ -800,6 +800,8 @@ typedef struct MDBX_lockinfo {
#define MDBX_PGL_LIMIT (MAX_MAPSIZE32 / MIN_PAGESIZE) #define MDBX_PGL_LIMIT (MAX_MAPSIZE32 / MIN_PAGESIZE)
#endif /* MDBX_WORDBITS */ #endif /* MDBX_WORDBITS */
#define MDBX_RADIXSORT_THRESHOLD 333
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* An PNL is an Page Number List, a sorted array of IDs. /* An PNL is an Page Number List, a sorted array of IDs.
@ -839,7 +841,6 @@ typedef struct MDBX_dpl {
/* PNL sizes */ /* PNL sizes */
#define MDBX_PNL_GRANULATE 1024 #define MDBX_PNL_GRANULATE 1024
#define MDBX_PNL_RADIXSORT_THRESHOLD 1024
#define MDBX_PNL_INITIAL \ #define MDBX_PNL_INITIAL \
(MDBX_PNL_GRANULATE - 2 - MDBX_ASSUME_MALLOC_OVERHEAD / sizeof(pgno_t)) (MDBX_PNL_GRANULATE - 2 - MDBX_ASSUME_MALLOC_OVERHEAD / sizeof(pgno_t))