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

Directly store score as double in the dict of zset. #959

Open
wants to merge 3 commits into
base: unstable
Choose a base branch
from

Conversation

RayaCoo
Copy link
Contributor

@RayaCoo RayaCoo commented Aug 28, 2024

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 for zunion[store] command, value of dict has been set twice. like this :

else if (op == SET_OP_UNION) {
    ...
    dictSetDoubleVal(de, score);
    ...
    dictSetVal(dstzset->dict, de, &znode->score);
    ...
}

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.

Copy link

codecov bot commented Aug 28, 2024

Codecov Report

Attention: Patch coverage is 96.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 70.56%. Comparing base (2d1eca5) to head (eb7cbc3).

Files with missing lines Patch % Lines
src/module.c 0.00% 2 Missing ⚠️
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     
Files with missing lines Coverage Δ
src/aof.c 80.05% <100.00%> (ø)
src/db.c 88.41% <100.00%> (ø)
src/debug.c 53.67% <100.00%> (ø)
src/defrag.c 86.58% <100.00%> (+0.82%) ⬆️
src/geo.c 93.48% <100.00%> (+0.01%) ⬆️
src/rdb.c 75.43% <100.00%> (-0.88%) ⬇️
src/t_zset.c 95.52% <100.00%> (-0.13%) ⬇️
src/module.c 9.64% <0.00%> (ø)

... and 12 files with indirect coverage changes

@RayaCoo RayaCoo force-pushed the zset-dict-double branch 2 times, most recently from 4f2361a to cad722d Compare August 28, 2024 15:30
src/dict.c Outdated Show resolved Hide resolved
src/dict.c Outdated
Comment on lines 535 to 543
/* 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;
}

Copy link
Contributor

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(...);

Copy link
Contributor Author

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.

@RayaCoo RayaCoo requested a review from hpatro September 4, 2024 11:30
@hpatro
Copy link
Contributor

hpatro commented Sep 4, 2024

@RayaCoo Could you run some benchmark around this to check if there is any performance gain?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Candidate for release
Development

Successfully merging this pull request may close these issues.

3 participants