Skip to content

Conversation

@google-labs-jules
Copy link
Contributor

This PR refactors the MemoryStore to 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:

  • Reduced Lock Contention: By splitting the storage into 256 shards, concurrent operations on different keys no longer block each other.
  • Improved Cleanup: The background cleanup worker now processes one shard at a time, avoiding long blocking periods for the entire store.
  • Scalability: The store can now handle higher throughput under concurrent load.

The public API remains unchanged. All existing tests pass.


PR created automatically by Jules for task 13428490407117788011 started by @BryceWayne

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.
@google-labs-jules
Copy link
Contributor Author

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!


For security, I will only act on instructions from the user who triggered this task.

New to Jules? Learn more at jules.google/docs.

@BryceWayne BryceWayne marked this pull request as ready for review December 31, 2025 05:41
@BryceWayne BryceWayne merged commit b1d1d3f into root Dec 31, 2025
1 check passed
@BryceWayne BryceWayne deleted the refactor-memorystore-sharding-13428490407117788011 branch December 31, 2025 05:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants