Improve performance #3476#3532
Improve performance #3476#3532ReneWerner87 merged 10 commits intogofiber:codex/refactor-context-and-routing-interfaces-for-genericsfrom
Conversation
goos: darwin
goarch: arm64
pkg: github.com/gofiber/fiber/v3
cpu: Apple M4
│ old.txt │ new.txt │
│ sec/op │ sec/op vs base │
_Communication_Flow-10 36.26n ± 0% 34.51n ± 0% -4.83% (p=0.000 n=30)
│ old.txt │ new.txt │
│ B/op │ B/op vs base │
_Communication_Flow-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=30) ¹
¹ all samples are equal
│ old.txt │ new.txt │
│ allocs/op │ allocs/op vs base │
_Communication_Flow-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=30) ¹
¹ all samples are equal
```
goos: darwin
goarch: arm64
pkg: github.com/gofiber/fiber/v3
cpu: Apple M4
│ new.txt │ new4.txt │
│ sec/op │ sec/op vs base │
_Communication_Flow-10 34.51n ± 0% 30.02n ± 0% -13.01% (p=0.000 n=30)
│ new.txt │ new4.txt │
│ B/op │ B/op vs base │
_Communication_Flow-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=30) ¹
¹ all samples are equal
│ new.txt │ new4.txt │
│ allocs/op │ allocs/op vs base │
_Communication_Flow-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=30) ¹
¹ all samples are equal
```
```
goos: darwin
goarch: arm64
pkg: github.com/gofiber/fiber/v3
cpu: Apple M4
│ head.txt │ revert-1.txt │
│ sec/op │ sec/op vs base │
_Communication_Flow-10 30.04n ± 0% 28.74n ± 0% -4.33% (p=0.000 n=30)
│ head.txt │ revert-1.txt │
│ B/op │ B/op vs base │
_Communication_Flow-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=30) ¹
¹ all samples are equal
│ head.txt │ revert-1.txt │
│ allocs/op │ allocs/op vs base │
_Communication_Flow-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=30) ¹
¹ all samples are equal
```
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 🗂️ Base branches to auto review (3)
Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Summary of Changes
Hello @ksw2000, 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 focuses on enhancing the overall performance and developer experience of the framework. Key changes include a significant refactor of the internal context and middleware handling, updates to core APIs for better usability, and various optimizations across different modules and middlewares. The changes also reflect an upgrade to a newer Go version and adherence to modern Go idioms.
Highlights
- Core Performance & API Refinements: Streamlined internal context handling by consolidating
nextandnextCustomlogic, improving efficiency of middleware chain execution. IntroducedNewWithCustomCtxfor more direct custom context initialization andNewErrorffor formatted error creation. - Go Version Update: The project now requires Go version
1.24or higher, aligning with newer language features and performance improvements. - Context (Ctx) Interface Enhancements: The
Ctxinterface now directly implementscontext.Context, providingDeadline(),Done(),Err(), andValue()methods. The previousContext()andSetContext()methods have been removed, simplifying context management. - Binder Module Optimizations: Improved performance in the binder module by utilizing
slices.Containsfor MIME type checks and implementing async.Mapbased caching mechanism forequalFieldTypelookups, reducing reflection overhead. - Middleware Updates & Cleanups: Various middlewares including
BasicAuth,Cache,EncryptCookie,KeyAuth,Limiter, andLoggerreceived updates. This includes improved header parsing, RFC compliance (e.g.,Ageheader in Cache), removal of deprecated configuration fields, and internal code cleanups. - Benchmarking Improvements: Updated numerous benchmarks to use
for b.Loop()and removed redundantb.ResetTimer()calls, ensuring more accurate and idiomatic performance measurements.
Using Gemini Code Assist
The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and 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 to provide feedback.
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
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
…ics' into fix-perf-3476
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## codex/refactor-context-and-routing-interfaces-for-generics #3532 +/- ##
==============================================================================================
- Coverage 91.05% 90.64% -0.41%
==============================================================================================
Files 110 110
Lines 10861 10926 +65
==============================================================================================
+ Hits 9889 9904 +15
- Misses 722 770 +48
- Partials 250 252 +2
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:
|
There was a problem hiding this comment.
Code Review
This pull request introduces significant performance improvements and API enhancements, primarily by refactoring the request handling and context management. Key changes include:
- Unified Request Handling: The
nextandrequestHandlerlogic inrouter.gohas been streamlined, which should reduce overhead and simplify the internal request flow. - Custom Context Enhancements: The introduction of
NewWithCustomCtxprovides a cleaner way to initialize apps with custom contexts. The internal dispatch for custom contexts within the main request handler is also refined. Ctxascontext.Context:DefaultCtxnow directly implementscontext.Context. This is a major API improvement, making Fiber's context more idiomatic. Consequently,Ctx.Context()andCtx.SetContext()have been removed, and standardcontext.Contextmethods (Deadline,Done,Err,Value) are now part of theCtxinterface (though some are nops due to fasthttp limitations).- Binding Optimizations: The
binder/mapping.gosees performance improvements with caching forequalFieldTypelookups. The use ofslices.Containsandmaps.Copyare welcome modernizations. - Robust Header Parsing: Middlewares like
basicauthandkeyauthnow have more robust parsing for Authorization headers. - Cache Middleware Enhancements: The cache middleware now respects server-side
Cache-Control: no-storeandmax-agedirectives, and adds an RFC-compliantAgeheader. - Generic Parsing Refactor: The
genericParseTypehelper has been refactored for better error reporting, with default value handling moved to its callers inctx.go. - Documentation & Go Version: Documentation has been updated extensively to reflect these changes, and the project's Go version has been bumped to 1.24.
Overall, these changes aim for better performance, a more idiomatic API, and increased robustness. The benchmark updates to use b.Loop() are also a good practice.
…ics' into fix-perf-3476
b8a0ed0
into
gofiber:codex/refactor-context-and-routing-interfaces-for-generics
* Make custom context setup via NewWithCustomCtx * Update docs/api/app.md * fix lint issues * small optimizations * Fix perf 3476 (#3499) * perf: modify app.pool goos: darwin goarch: arm64 pkg: github.com/gofiber/fiber/v3 cpu: Apple M4 │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ _Communication_Flow-10 36.26n ± 0% 34.51n ± 0% -4.83% (p=0.000 n=30) │ old.txt │ new.txt │ │ B/op │ B/op vs base │ _Communication_Flow-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=30) ¹ ¹ all samples are equal │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ _Communication_Flow-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=30) ¹ ¹ all samples are equal * perf: optimize defaultCtx in app.next ``` goos: darwin goarch: arm64 pkg: github.com/gofiber/fiber/v3 cpu: Apple M4 │ new.txt │ new4.txt │ │ sec/op │ sec/op vs base │ _Communication_Flow-10 34.51n ± 0% 30.02n ± 0% -13.01% (p=0.000 n=30) │ new.txt │ new4.txt │ │ B/op │ B/op vs base │ _Communication_Flow-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=30) ¹ ¹ all samples are equal │ new.txt │ new4.txt │ │ allocs/op │ allocs/op vs base │ _Communication_Flow-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=30) ¹ ¹ all samples are equal ``` --------- Co-authored-by: Kashiwa <13825170+ksw2000@users.noreply.github.com> * Improve performance #3476 (#3532) * Make custom context setup via NewWithCustomCtx * Update docs/api/app.md * fix lint issues * small optimizations * perf: modify app.pool goos: darwin goarch: arm64 pkg: github.com/gofiber/fiber/v3 cpu: Apple M4 │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ _Communication_Flow-10 36.26n ± 0% 34.51n ± 0% -4.83% (p=0.000 n=30) │ old.txt │ new.txt │ │ B/op │ B/op vs base │ _Communication_Flow-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=30) ¹ ¹ all samples are equal │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ _Communication_Flow-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=30) ¹ ¹ all samples are equal * perf: optimize defaultCtx in app.next ``` goos: darwin goarch: arm64 pkg: github.com/gofiber/fiber/v3 cpu: Apple M4 │ new.txt │ new4.txt │ │ sec/op │ sec/op vs base │ _Communication_Flow-10 34.51n ± 0% 30.02n ± 0% -13.01% (p=0.000 n=30) │ new.txt │ new4.txt │ │ B/op │ B/op vs base │ _Communication_Flow-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=30) ¹ ¹ all samples are equal │ new.txt │ new4.txt │ │ allocs/op │ allocs/op vs base │ _Communication_Flow-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=30) ¹ ¹ all samples are equal ``` * perf: revert nextCustom ``` goos: darwin goarch: arm64 pkg: github.com/gofiber/fiber/v3 cpu: Apple M4 │ head.txt │ revert-1.txt │ │ sec/op │ sec/op vs base │ _Communication_Flow-10 30.04n ± 0% 28.74n ± 0% -4.33% (p=0.000 n=30) │ head.txt │ revert-1.txt │ │ B/op │ B/op vs base │ _Communication_Flow-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=30) ¹ ¹ all samples are equal │ head.txt │ revert-1.txt │ │ allocs/op │ allocs/op vs base │ _Communication_Flow-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=30) ¹ ¹ all samples are equal ``` --------- Co-authored-by: RW <rene@gofiber.io> --------- Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Co-authored-by: Kashiwa <13825170+ksw2000@users.noreply.github.com>
Description
Improve the performance of #3476 by using
nextCustomandnextseparatelyType 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.