-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
🧹 chore: Skip locking garbage collector if nothing to delete #3787
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
Signed-off-by: Artur Melanchyk <[email protected]>
This reverts commit 25df78f.
Signed-off-by: Artur Melanchyk <[email protected]>
WalkthroughIntroduces an early-continue in the in-memory storage garbage collector loop to skip acquiring the write lock when no expired items are found. No public APIs or signatures are changed; only internal control flow in the GC path is adjusted. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant T as GC Ticker
participant M as MemoryStore
participant R as Read Lock
participant W as Write Lock
T->>M: Tick
M->>R: Acquire read lock
M->>M: Scan for expired items
alt No expired items
M-->>R: Release read lock
Note right of M: Early continue (no write lock)
else Expired items found
M-->>R: Release read lock
M->>W: Acquire write lock
M->>M: Delete expired items
M-->>W: Release write lock
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3787 +/- ##
=======================================
Coverage 91.67% 91.67%
=======================================
Files 113 113
Lines 11959 11959
=======================================
Hits 10964 10964
Misses 731 731
Partials 264 264
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
/gemini review |
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 optimizes the garbage collector in the memory storage by avoiding unnecessary write lock acquisition when there are no expired entries to delete.
- Adds a check to skip locking when the expired entries slice is empty
- Improves performance by reducing lock contention in scenarios with no expired data
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.
Code Review
This pull request introduces a sensible optimization to the garbage collector in the in-memory storage. The change avoids acquiring a write lock when there are no expired items to delete, which should reduce lock contention. The implementation is correct, and my review includes one comment regarding the validation of this performance improvement.
gaby
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.
👍 LGTM
…#3787) Co-authored-by: Artur Melanchyk <[email protected]>
Description
Avoid entering lock when there is no expired entries
Changes introduced
List the new features or adjustments introduced in this pull request. Provide details on benchmarks, documentation updates, changelog entries, and if applicable, the migration guide.
Type of change
Please delete options that are not relevant.
Checklist
Before you submit your pull request, please make sure you meet these requirements:
/docs/directory for Fiber's documentation.Commit formatting
Please use emojis in commit messages for an easy way to identify the purpose or intention of a commit. Check out the emoji cheatsheet here: CONTRIBUTING.md