[BUGFIX] shard distribution bias due to the key length and its stucture#148
[BUGFIX] shard distribution bias due to the key length and its stucture#148
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request attempts to fix shard distribution bias in the cache by introducing configurable key length hashing and optimizing the hash function selection. The PR also includes widespread refactoring to modernize Go syntax patterns (using for range N and any instead of interface{}), simplify concurrency patterns, and utilize standard library improvements like maps.Copy.
Changes:
- Introduced
maxKeyLengthoption to control how many bytes of keys are used for shard distribution hashing, with dynamic selection betweenmaphash(for ≤32 bytes) andxxh3(for longer keys) - Refactored iteration patterns from
for i := 0; i < N; i++tofor range Nthroughout the codebase - Attempted to simplify concurrent operations by replacing
wg.Add(1)andwg.Done()with non-existentwg.Go()method
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| gache.go | Core changes to shard ID calculation with new maxKeyLength field and modified getShardID function; attempted refactoring of ToMap concurrency pattern |
| option.go | Added WithMaxKeyLength option for configuring hash key length |
| gache_benchmark_test.go | Modernized type signatures (interface{} to any) and attempted concurrency refactoring |
| map_bench_test.go | Refactored loops to use for range N pattern |
| map_size_noswiss_test.go | Refactored loops to use for range N pattern |
| map_size_noswiss.go | Refactored loops to use for range len(slice) pattern |
| map_reference_test.go | Simplified map copying using maps.Copy from standard library |
| example/main.go | Updated type signatures and loop patterns for consistency |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b81381a to
1875383
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot open a new pull request to apply changes based on the comments in this thread |
6a8a70b to
5fb0b59
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 14 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
9692fb0 to
e6ed2a3
Compare
Signed-off-by: kpango <kpango@vdaas.org>
e6ed2a3 to
25c9cc2
Compare
This pull request introduces several improvements and refactors across the codebase, focusing on optimizing iteration patterns, enhancing type usage, and improving hashing strategies in the main cache implementation. The most significant changes include replacing traditional
forloops withfor rangefor better readability and performance, updating type declarations to useany, and refining the hashing logic for cache sharding.Refactoring and Optimization:
for i := 0; i < N; i++ { ... }loops withfor i := range N { ... }in the main code, benchmarks, and tests for improved readability and potential performance benefits. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25]Type Improvements:
gache_benchmark_test.goto useanyinstead ofinterface{}for better Go 1.18+ compatibility and clarity.example/main.gofrominterface{}toany.Hashing and Sharding Enhancements:
maxKeyLengthin thegachestruct and changed the shard ID calculation to usemaphashfor keys up to 32 bytes andxxh3for longer keys, improving hashing performance and flexibility. [1] [2] [3]get,set,Delete) to use the new shard ID calculation withmaxKeyLength. [1] [2] [3]Concurrency Improvements:
ToMapand benchmarks to usewg.Goinstead of manualwg.Addandwg.Done, simplifying concurrency handling. [1] [2] [3] [4] [5]Standard Library Usage:
maps.Copyfunction inmap_reference_test.goto simplify copying maps. [1] [2]