Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize ZUNION[STORE] command by removing unnecessary accumulator di…
…ct (valkey-io#829) In the past implementation of `ZUNION` and `ZUNIONSTORE` commands, we first create a temporary dict called `accumulator`. After adding all member-score mappings to `accumulator`, we still need to convert `accumulator` back to the final dict `dstzset->dict`. However, we can directly use `dstzset->dict` to avoid the additional copy operation. This PR removes the `accumulator` dict and directly uses` dstzset->dict `to store the member-score mappings. - **Test** First, I added 300 unique elements to two sorted sets called 'zunion_test1' and 'zunion_test2'. Then, I tested `zunion` and `zunionstore` on these two sorted sets. The test results shown below indicate that the performance of both zunion and zunionstore improved about 31%. ### ZUNION #### unstable ``` ./valkey-benchmark -P 10 -n 100000 zunion 2 zunion_test1 zunion_test2 Summary: throughput summary: 2713.41 requests per second latency summary (msec): avg min p50 p95 p99 max 146.252 3.464 153.343 182.015 184.959 192.895 ``` #### This PR ``` ./valkey-benchmark -P 10 -n 100000 zunion 2 zunion_test1 zunion_test2 Summary: throughput summary: 3543.84 requests per second latency summary (msec): avg min p50 p95 p99 max 108.259 2.984 114.239 141.695 145.151 160.255 ``` ### ZUNIONSTORE #### unstable ``` ./valkey-benchmark -P 10 -n 100000 zunionstore out 2 zunion_test1 zunion_test2 Summary: throughput summary: 3168.07 requests per second latency summary (msec): avg min p50 p95 p99 max 157.511 3.368 183.167 189.311 193.535 231.679 ``` #### This PR ``` ./valkey-benchmark -P 10 -n 100000 zunionstore out 2 zunion_test1 zunion_test2 Summary: throughput summary: 4144.73 requests per second latency summary (msec): avg min p50 p95 p99 max 120.374 2.648 141.823 149.119 153.855 183.167 ``` --------- Signed-off-by: RayCao <[email protected]> Signed-off-by: zisong.cw <[email protected]> Signed-off-by: mwish <[email protected]>
- Loading branch information