Fix perf 3476#3499
Fix perf 3476#3499ReneWerner87 merged 2 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
```
|
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.
Pull Request Overview
This PR focuses on performance improvements and code refactoring for route handling in the application. Key changes include reusing the tree path hash to avoid duplicate computations, integrating the method scanning logic into the main route matching function (with the removal of the separate helper), and updating context interface methods to work with CustomCtx.
- Reused treeHash variable in route matching.
- Inlined method existence scanning logic.
- Updated AcquireCtx/ReleaseCtx type signatures and pool creation.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| router.go | Refactored route matching and method scanning for performance. |
| helpers.go | Removed the unused methodExist helper function. |
| ctx_interface.go | Changed AcquireCtx/ReleaseCtx to return/accept CustomCtx. |
| app.go | Updated ctx pool creation to align with new context creation logic. |
Comments suppressed due to low confidence (2)
ctx_interface.go:49
- The panic error message still refers to 'Ctx' instead of 'CustomCtx'. Consider updating the message to accurately reflect the expected type.
if !ok { panic(errors.New("failed to type-assert to Ctx")) }
router.go:173
- The new return statement in the route matching loop bypasses error propagation from routes with no handlers. Please verify that this change is intended and does not suppress important error conditions.
return true, nil // Stop scanning the stack
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## codex/refactor-context-and-routing-interfaces-for-generics #3499 +/- ##
==============================================================================================
- Coverage 84.78% 84.76% -0.03%
==============================================================================================
Files 120 120
Lines 12063 12073 +10
==============================================================================================
+ Hits 10228 10234 +6
- Misses 1417 1420 +3
- Partials 418 419 +1
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:
|
4bacc1a
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>


No description provided.