Refactor MemoryStore to use sharded storage#11
Conversation
Refactored `MemoryStore` to use a sharded map approach (Concurrent Map pattern) with 256 shards. This reduces lock contention significantly compared to the previous single global lock design. Changes: - Replaced `mu` and `store` with `shards` slice in `MemoryStore`. - Implemented `shard` struct with individual mutex and map. - Added `getShard` method using FNV-1a hashing. - Updated `Set`, `Get`, `Delete` to operate on specific shards. - Optimized `SetMulti` and `GetMulti` to group keys by shard. - Updated `cleanupExpiredItems` to iterate and lock shards individually, preventing "stop-the-world" pauses. - Preserved lifecycle management using a dedicated `lifecycleMu`. - Updated `GetMetrics` to aggregate stats from all shards.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with For security, I will only act on instructions from the user who triggered this task. New to Jules? Learn more at jules.google/docs. |
This PR refactors the
MemoryStoreto use a sharded storage architecture (Striped Locking) instead of a single global mutex. This change addresses the user's request for a better design pattern to handle concurrency.Key improvements:
The public API remains unchanged. All existing tests pass.
PR created automatically by Jules for task 13428490407117788011 started by @BryceWayne