Replace dict with thin wrapper around hashtable#3366
Replace dict with thin wrapper around hashtable#3366zuiderkwast wants to merge 5 commits intovalkey-io:unstablefrom
Conversation
Stop overriding libvalkey's dict with valkey's. Remove the DICT_INCLUDE_DIR mechanism from libvalkey's build system since it is no longer needed. Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Data hashtables (keys, sets, zsets, hashes) now use a configurable seed separate from the global hashtable seed. This allows the hash-seed config to control SCAN iteration order without affecting internal hashtables (commands, ACL, modules, etc.) that are populated before config loading. The configurable seed defaults to the random seed and is overridden after config loading if hash-seed is set. Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## unstable #3366 +/- ##
============================================
- Coverage 74.46% 74.38% -0.09%
============================================
Files 130 129 -1
Lines 72730 72303 -427
============================================
- Hits 54160 53781 -379
+ Misses 18570 18522 -48
🚀 New features to boost your workflow:
|
Replace the dict.c implementation with a header-only wrapper (dict.h) around the hashtable API. The dict types, iterators and API functions are now typedefs, macros and inline functions that delegate to hashtable. This unifies the hashtable implementations in the project and removes duplicated logic. Changes to dict: - Remove dict.c; dict.h is now the entire implementation - dict, dictType and dictIterator are direct aliases for the hashtable counterparts. - dictEntry is a struct allocated by dict wrapper functions to hold key and value. It doesn't have a next pointer anymore. - Fix key duplication for dictTypes that had keyDup callback by calling sdsdup() at call sites in functions.c - Remove unused functions, macros, includes and casts - Move some dict defrag logic to defrag.c - Remove obsolete dict unit tests (covered by test_hashtable.cpp) Changes to hashtable: - Change hashtable keyCompare convention to match dict: non-zero means keys are equal, so existing dict compare functions can be reused - Add const to hashtableMemUsage parameter Changes to server implementation: - Deduplicate common dict/hashtable callbacks in server.c Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
rainsupreme
left a comment
There was a problem hiding this comment.
The code looks good to me! I'd like to see the benchmark results, otherwise looks good to go! 😁
There was a problem hiding this comment.
Awesome work! My only concern was always allocating new entry before checking if key exists in dictReplace() and freeing new entry if key already exists. But this function is not that frequently used so impact is minimal.
BTW for module dict API should we mention somewhere that now its another implementation?
Exactly, that was my conclusion too, so it's fine.
It's a rax! Crazy... but it's not affected by this PR. |
sarthakaggarwal97
left a comment
There was a problem hiding this comment.
Minor comments! Looks pretty goood!
Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
|
Benchmark ran on this commit: Benchmark Comparison: unstable vs 8ca73b3 (averaged) - rps metricsRun Summary:
Statistical Notes:
Note: Values with (n=X, σ=Y, CV=Z%, CI99%=±W%, PI99%=±V%) indicate averages from X runs with standard deviation Y, coefficient of variation Z%, 99% confidence interval margin of error ±W% of the mean, and 99% prediction interval margin of error ±V% of the mean. CI bounds [A, B] and PI bounds [C, D] show the actual interval ranges. Configuration:
Configuration:
|
Replace the dict.c implementation with a header-only wrapper (dict.h)
around the hashtable API. The dict types, iterators and API functions
are now typedefs, macros and inline functions that delegate to hashtable.
This unifies the hashtable implementations in the project and removes
duplicated logic.
Changes to dict:
counterparts.
and value. It doesn't have a next pointer anymore.
calling sdsdup() at call sites in functions.c
Changes to hashtable:
keys are equal, so existing dict compare functions can be reused
Changes to server implementation:
particular, it must not modify the hash seed for dicts already
initialized during startup for reading configs and similar.
Changes to libvalkey: