Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove lpAssertValidEntry from listpack functions to achieve up to 10% improvement on HSET command. #399

Open
wants to merge 1 commit into
base: unstable
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 1 addition & 17 deletions src/listpack.c
Expand Up @@ -137,8 +137,6 @@
assert((p) >= (lp)+LP_HDR_SIZE && (p)+(len) < (lp)+lpGetTotalBytes((lp))); \
} while (0)

static inline void lpAssertValidEntry(unsigned char* lp, size_t lpbytes, unsigned char *p);

/* Don't let listpacks grow over 1GB in any case, don't wanna risk overflow in
* Total Bytes header field */
#define LISTPACK_MAX_SAFETY_SIZE (1<<30)
Expand Down Expand Up @@ -475,7 +473,6 @@ unsigned char *lpNext(unsigned char *lp, unsigned char *p) {
assert(p);
p = lpSkip(p);
if (p[0] == LP_EOF) return NULL;
lpAssertValidEntry(lp, lpBytes(lp), p);
return p;
}

Expand All @@ -489,7 +486,6 @@ unsigned char *lpPrev(unsigned char *lp, unsigned char *p) {
uint64_t prevlen = lpDecodeBacklen(p);
prevlen += lpEncodeBacklen(NULL,prevlen);
p -= prevlen-1; /* Seek the first byte of the previous entry. */
lpAssertValidEntry(lp, lpBytes(lp), p);
return p;
}

Expand All @@ -498,7 +494,6 @@ unsigned char *lpPrev(unsigned char *lp, unsigned char *p) {
unsigned char *lpFirst(unsigned char *lp) {
unsigned char *p = lp + LP_HDR_SIZE; /* Skip the header. */
if (p[0] == LP_EOF) return NULL;
lpAssertValidEntry(lp, lpBytes(lp), p);
return p;
}

Expand Down Expand Up @@ -731,17 +726,12 @@ unsigned char *lpFind(unsigned char *lp, unsigned char *p, unsigned char *s,
} else {
/* Skip entry */
skipcnt--;

/* Move to next entry, avoid use `lpNext` due to `lpAssertValidEntry` in
* `lpNext` will call `lpBytes`, will cause performance degradation */
p = lpSkip(p);
}

/* The next call to lpGetWithSize could read at most 8 bytes past `p`
* We use the slower validation call only when necessary. */
if (p + 8 >= lp + lp_bytes)
lpAssertValidEntry(lp, lp_bytes, p);
else
if (p + 8 < lp + lp_bytes)
assert(p >= lp + LP_HDR_SIZE && p < lp + lp_bytes);
if (p[0] == LP_EOF) break;
}
Expand Down Expand Up @@ -1013,7 +1003,6 @@ unsigned char *lpDeleteRangeWithEntry(unsigned char *lp, unsigned char **p, unsi
deleted++;
tail = lpSkip(tail);
if (tail[0] == LP_EOF) break;
lpAssertValidEntry(lp, bytes, tail);
}

/* Store the offset of the element 'first', so that we can obtain its
Expand Down Expand Up @@ -1337,11 +1326,6 @@ int lpValidateNext(unsigned char *lp, unsigned char **pp, size_t lpbytes) {
#undef OUT_OF_RANGE
}

/* Validate that the entry doesn't reach outside the listpack allocation. */
static inline void lpAssertValidEntry(unsigned char* lp, size_t lpbytes, unsigned char *p) {
assert(lpValidateNext(lp, &p, lpbytes));
}

/* Validate the integrity of the data structure.
* when `deep` is 0, only the integrity of the header is validated.
* when `deep` is 1, we scan all the entries one by one. */
Expand Down