-
Notifications
You must be signed in to change notification settings - Fork 600
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
Directly store score as double in the dict of zset. #959
base: unstable
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## unstable #959 +/- ##
============================================
+ Coverage 70.39% 70.56% +0.16%
============================================
Files 114 114
Lines 61634 61643 +9
============================================
+ Hits 43388 43499 +111
+ Misses 18246 18144 -102
|
4f2361a
to
cad722d
Compare
Signed-off-by: Ray Cao <[email protected]>
cad722d
to
bb97035
Compare
src/dict.c
Outdated
/* Add an element with double value to the target hash table */ | ||
int dictAddDoubleVal(dict *d, void *key, double val) { | ||
dictEntry *entry = dictAddRaw(d, key, NULL); | ||
|
||
if (!entry) return DICT_ERR; | ||
if (!d->type->no_value) dictSetDoubleVal(entry, val); | ||
return DICT_OK; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to introduce this new method and expose it. Rather you could do it in a pair of operation, create a dict entry and set the value.
dictAddRaw(...);
dictSetDoubleVal(...);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your advice, the dictSetDoubleVal
function has been removed.
Signed-off-by: Ray Cao <[email protected]>
Signed-off-by: Rayacoo <[email protected]>
@RayaCoo Could you run some benchmark around this to check if there is any performance gain? |
In the past, we used
void *
for dict to store the score of elements in zset. This mean we had to dereference the score ervey time we accesse it. For example,*(double *)dictGetVal(de)
. This added extra dereference overhead, and forzunion[store]
command, value of dict has been set twice. like this :Since double field has been add in dictEntry value union by commit, and for zset, the value stored in dict will always be double type, we can directly store score as double, which can improves the code's readability and reduces extra dereferencing overhead.