Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@arturmelanchyk
Copy link
Contributor

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.

  • Benchmarks: Describe any performance benchmarks and improvements related to the changes.
  • Documentation Update: Detail the updates made to the documentation and links to the changed files.
  • Changelog/What's New: Include a summary of the additions for the upcoming release notes.
  • Migration Guide: If necessary, provide a guide or steps for users to migrate their existing code to accommodate these changes.
  • API Alignment with Express: Explain how the changes align with the Express API.
  • API Longevity: Discuss the steps taken to ensure that the new or updated APIs are consistent and not prone to breaking changes.
  • Examples: Provide examples demonstrating the new features or changes in action.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • Enhancement (improvement to existing features and functionality)
  • Documentation update (changes to documentation)
  • Performance improvement (non-breaking change which improves efficiency)
  • Code consistency (non-breaking change which improves code reliability and robustness)

Checklist

Before you submit your pull request, please make sure you meet these requirements:

  • Followed the inspiration of the Express.js framework for new functionalities, making them similar in usage.
  • Conducted a self-review of the code and provided comments for complex or critical parts.
  • Updated the documentation in the /docs/ directory for Fiber's documentation.
  • Added or updated unit tests to validate the effectiveness of the changes or new features.
  • Ensured that new and existing unit tests pass locally with the changes.
  • Verified that any new dependencies are essential and have been agreed upon by the maintainers/community.
  • Aimed for optimal performance with minimal allocations in the new code.
  • Provided benchmarks for the new code to analyze and improve upon.

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

@arturmelanchyk arturmelanchyk changed the title Avoid lock 🧹 chore: avoid locking in gc() if nothing to delete Oct 5, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 5, 2025

Walkthrough

Introduces 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

Cohort / File(s) Summary of Changes
Memory storage GC control flow
internal/storage/memory/memory.go
Added a pre-check for expired items in the GC loop; if none are detected, the loop continues without acquiring the write lock. No exported declarations changed.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

🧹 Updates

Suggested reviewers

  • sixcolors
  • ReneWerner87
  • efectn
  • gaby

Poem

A tick-tock hops through memory glen,
I sniff for crumbs that stale have been—
None? I twitch and bounce ahead,
No lock, no fuss, no sleepy dread.
When rot appears, I tidy tight—
A neat, swift sweep by moonlit byte. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The description follows the template structure but fails to provide required details such as linked issue fixes, concrete descriptions in the “Changes introduced” section, filled benchmarks, documentation updates, changelog entries, migration steps, examples, and confirmation that checklist items like tests passing have been addressed. Please fill in the issue number in “Fixes #”, supply detailed entries under “Changes introduced” for benchmarks, documentation updates, changelog, migration guide, and examples, and mark checklist items such as added tests, successful local test runs, and performance benchmarks to fully satisfy the PR template.
✅ Passed checks (2 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Title Check ✅ Passed The title accurately describes the primary change by indicating that the garbage collector will skip acquiring a lock when there is nothing to delete, which matches the code modification adding an early continue in gc(). It is concise, clear, and specific, and avoids vague or generic wording. The emoji chore prefix aligns with the project's commit formatting guidelines. Therefore, the title clearly conveys the main intent of the changeset.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Oct 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.67%. Comparing base (e8f639a) to head (76b259c).
⚠️ Report is 5 commits behind head on main.

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           
Flag Coverage Δ
unittests 91.67% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@arturmelanchyk arturmelanchyk marked this pull request as ready for review October 5, 2025 19:30
@arturmelanchyk arturmelanchyk requested a review from a team as a code owner October 5, 2025 19:30
@gaby gaby changed the title 🧹 chore: avoid locking in gc() if nothing to delete 🧹 chore: Skip locking garbage collector if nothing to delete Oct 5, 2025
@gaby gaby added 🧹 Updates v3 hacktoberfest 🚀 Open for Hacktoberfest contributions! labels Oct 5, 2025
@gaby gaby added this to v3 Oct 5, 2025
@gaby gaby added this to the v3 milestone Oct 5, 2025
@gaby gaby requested a review from Copilot October 5, 2025 22:38
@gaby
Copy link
Member

gaby commented Oct 5, 2025

/gemini review

Copy link
Contributor

Copilot AI left a 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

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

Copy link
Member

@gaby gaby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 LGTM

@ReneWerner87 ReneWerner87 merged commit 6f81d52 into gofiber:main Oct 6, 2025
16 checks passed
@github-project-automation github-project-automation bot moved this to Done in v3 Oct 6, 2025
Abhirup-99 pushed a commit to Abhirup-99/fiber that referenced this pull request Nov 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hacktoberfest 🚀 Open for Hacktoberfest contributions! 🧹 Updates v3

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants