♻️ Refactor: reduce the memory usage of cacheableStatusCodes#3789
♻️ Refactor: reduce the memory usage of cacheableStatusCodes#3789ReneWerner87 merged 1 commit intogofiber:mainfrom
Conversation
WalkthroughReplaced a map[int]bool with map[int]struct{} for cacheable HTTP status codes in middleware/cache/cache.go and updated lookup logic to use presence checks. Status code set remains unchanged; only the data structure and access pattern were modified. Changes
Sequence Diagram(s)Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (1)**/*.go📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧬 Code graph analysis (1)middleware/cache/cache.go (1)
⏰ 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)
🔇 Additional comments (3)
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 |
Summary of ChangesHello @ZihxS, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refactors the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This is an excellent pull request that refactors cacheableStatusCodes to use the idiomatic Go pattern map[int]struct{} for representing a set. This change correctly reduces memory usage and improves code clarity by signaling that only key presence matters. The logic for checking status code cacheability has been updated appropriately. The pull request description is very clear and includes benchmark results to support the change. The implementation is correct and follows best practices. I have no further suggestions; great work!
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3789 +/- ##
=======================================
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:
|
Description
Replace map[int]bool with map[int]struct{} for the cacheableStatusCodes set.
Why?
map[int]struct{} is the idiomatic Go pattern for representing sets (collections where only key presence matters).
It reduces memory usage slightly by avoiding storage of unnecessary boolean values (struct{} is zero-sized).
Benchmarking confirms:
Custom Demo Benchmark:

Bencmark_Cache (BEFORE):

Bencmark_Cache (AFTER):

Impact:
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