-
Notifications
You must be signed in to change notification settings - Fork 2
Feature/slice based radix #17
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
Conversation
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.
Pull request overview
This PR introduces a new KVCache implementation using a slice-based radix trie instead of the existing map-based wrapper (KV). The primary goals are to reduce memory consumption and improve search performance at the trie node level, while eliminating the extra mutex overhead from the wrapped cache approach.
Key Changes
- Added
KVCachewith slice-based radix trie implementation for memory efficiency - Updated
RingBuffer.All()to use exclusive lock instead of read lock - Enhanced benchmarks with new test cases and more realistic composite key patterns
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| kv_cache.go | New slice-based radix trie cache implementation with terminal nodes and freelist for value reuse |
| kv_cache_test.go | Comprehensive test suite including unit tests, fuzz tests, and concurrency tests for KVCache |
| bench_test.go | Added KVCache to benchmark suite and enhanced test data generation with composite keys |
| ring.go | Changed All() iterator from RLock to exclusive Lock |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #17 +/- ##
===========================================
- Coverage 100.00% 97.98% -2.02%
===========================================
Files 7 8 +1
Lines 790 1190 +400
===========================================
+ Hits 790 1166 +376
- Misses 0 18 +18
- Partials 0 6 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
egregors
left a comment
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.
I trust you have diligently checked every line with a looking glass 🕵️ |
| func (kv *KVCache[K, V]) get(key K) (V, bool) { | ||
| node := kv.trie | ||
| keyBytes := []byte(key) | ||
|
|
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.
add same logic as insert
if len(keyBytes) == 0 {
if node.terminal {
return kv.values[node.valueIndex], true
}
return kv.zero, false
}
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.
I did this instead:
if node.terminal {
return kv.values[node.valueIndex], true
}
return kv.zero, false
Add a separate
KVCachewith slice based radix implementation (compared to map based wrapper that isKV).The idea is to cut on memory consumption as well as search time on the trie node level (small maps access is not faster than small slices, and max map size on node level is 256).
And by making it a separate cache size we are cutting down on extra mutex in the wrapped cache.