Skip to content

🧹 chore: avoid locking in gc() if nothing to delete#3765

Merged
gaby merged 1 commit intogofiber:mainfrom
arturmelanchyk:storage
Sep 27, 2025
Merged

🧹 chore: avoid locking in gc() if nothing to delete#3765
gaby merged 1 commit intogofiber:mainfrom
arturmelanchyk:storage

Conversation

@arturmelanchyk
Copy link
Contributor

Description

Avoid unneeded locking in gc()

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 26, 2025

Walkthrough

The gc routine in internal/memory/memory.go adds an early continue when no expired entries are found, skipping acquisition of the write lock. Control flow is adjusted only within the garbage collection path. No exported APIs or error handling are changed.

Changes

Cohort / File(s) Summary
Memory GC control-flow
internal/memory/memory.go
gc now checks for expired entries and continues early when none exist, avoiding write-lock acquisition; internal control flow updated without modifying public interfaces.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant T as Ticker/Timer
    participant M as MemoryStore
    participant R as RWMutex

    T->>M: Trigger gc()
    M->>M: Scan for expired entries
    alt Expired entries found
        M->>R: Acquire write lock
        M->>M: Delete expired keys
        M-->>R: Release write lock
    else No expired entries
        note right of M: New behavior: continue early\n(no write lock)
    end
    M-->>T: GC cycle completes
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I hop through heaps where keys once stayed,
Sniff—no stales? I’m on my way!
No locks to chew, no waits today,
Just breezy bounds in GC play.
When crumbs expire, I’ll tidy the trail—
Quick paw, clean cache, a whiskered exhale. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The description follows the repository template structure but leaves all sections unpopulated and fails to reference any related issue or detail the adjustments made. The placeholder checklist items under “Changes introduced” are untouched, and no benchmarks, documentation updates, or tests are documented, making the description incomplete. Complete the description by providing a clear overview of what the change does, reference any related issue number, and fill out or remove the placeholder checklist items to accurately reflect benchmarks, documentation updates, tests, and other relevant details.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title precisely summarizes the primary update to skip locking in gc() when there are no expired entries, reflecting the main change in the code. It is concise and specific, enabling a reviewer to understand the core improvement at a glance. The phrasing is clear and free of unnecessary detail.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0b0a4a4 and cfec12d.

📒 Files selected for processing (1)
  • internal/memory/memory.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

**/*.go: Format Go code using gofumpt (enforced via make format)
Ensure code passes golangci-lint checks (enforced via make lint)
Optimize struct field alignment using betteralign (enforced via make betteralign)
Modernize Go code using gopls modernize (enforced via make modernize)

Files:

  • internal/memory/memory.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: repeated
  • GitHub Check: unit (1.25.x, macos-13)
  • GitHub Check: unit (1.25.x, windows-latest)
  • GitHub Check: Compare
🔇 Additional comments (1)
internal/memory/memory.go (1)

90-93: LGTM – avoids needless writes

Skipping the write lock when there’s nothing to purge keeps GC iterations lighter without affecting correctness. ✅


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.

@arturmelanchyk arturmelanchyk marked this pull request as ready for review September 26, 2025 18:04
@arturmelanchyk arturmelanchyk requested a review from a team as a code owner September 26, 2025 18:04
@codecov
Copy link

codecov bot commented Sep 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.42%. Comparing base (0b0a4a4) to head (cfec12d).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3765   +/-   ##
=======================================
  Coverage   91.42%   91.42%           
=======================================
  Files         113      113           
  Lines       11874    11874           
=======================================
  Hits        10856    10856           
  Misses        750      750           
  Partials      268      268           
Flag Coverage Δ
unittests 91.42% <ø> (ø)

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.

@gaby gaby added this to v3 Sep 27, 2025
@gaby gaby added this to the v3 milestone Sep 27, 2025
@gaby gaby moved this to In Progress in v3 Sep 27, 2025
@gaby gaby merged commit 0224bae into gofiber:main Sep 27, 2025
16 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in v3 Sep 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants