summaryrefslogtreecommitdiff
path: root/src/listpack.h
diff options
context:
space:
mode:
authorOran Agra <oran@redislabs.com>2022-04-17 17:16:46 +0300
committerGitHub <noreply@github.com>2022-04-17 17:16:46 +0300
commit0c4733c8d7c50e0b0dc3373733fddfff3f62dda0 (patch)
tree5ecd20be1f6f9397539d42558b84f74a0800d87a /src/listpack.h
parentf49ff156ecd62aee104cff9f88fb62948575e6b0 (diff)
downloadredis-0c4733c8d7c50e0b0dc3373733fddfff3f62dda0.tar.gz
Optimize integer zset scores in listpack (converting to string and back) (#10486)
When the score doesn't have fractional part, and can be stored as an integer, we use the integer capabilities of listpack to store it, rather than convert it to string. This already existed before this PR (lpInsert dose that conversion implicitly). But to do that, we would have first converted the score from double to string (calling `d2string`), then pass the string to `lpAppend` which identified it as being an integer and convert it back to an int. Now, instead of converting it to a string, we store it using lpAppendInteger`. Unrelated: --- * Fix the double2ll range check (negative and positive ranges, and also the comparison operands were slightly off. but also, the range could be made much larger, see comment). * Unify the double to string conversion code in rdb.c with the one in util.c * Small optimization in lpStringToInt64, don't attempt to convert strings that are obviously too long. Benchmark; --- Up to 20% improvement in certain tight loops doing zzlInsert with large integers. (if listpack is pre-allocated to avoid realloc, and insertion is sorted from largest to smaller)
Diffstat (limited to 'src/listpack.h')
-rw-r--r--src/listpack.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/listpack.h b/src/listpack.h
index 6c4d6bdd6..3e750af5b 100644
--- a/src/listpack.h
+++ b/src/listpack.h
@@ -59,6 +59,8 @@ void lpFree(unsigned char *lp);
unsigned char* lpShrinkToFit(unsigned char *lp);
unsigned char *lpInsertString(unsigned char *lp, unsigned char *s, uint32_t slen,
unsigned char *p, int where, unsigned char **newp);
+unsigned char *lpInsertInteger(unsigned char *lp, long long lval,
+ unsigned char *p, int where, unsigned char **newp);
unsigned char *lpPrepend(unsigned char *lp, unsigned char *s, uint32_t slen);
unsigned char *lpPrependInteger(unsigned char *lp, long long lval);
unsigned char *lpAppend(unsigned char *lp, unsigned char *s, uint32_t slen);