-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v3: Improve Performance of c.Body() by 125% #3090
Conversation
WalkthroughThe changes enhance the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
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 as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- ctx.go (1 hunks)
- ctx_test.go (2 hunks)
Additional comments not posted (5)
ctx.go (3)
342-343
: Improvement: Direct retrieval ofContent-Encoding
header.The direct retrieval of the
Content-Encoding
header usingc.Request().Header.ContentEncoding()
improves performance by eliminating the need to iterate through all headers.
345-351
: Improvement: Streamlined handling for no encoding.The handling of cases where no encoding is provided is now more efficient. The code checks if
headerEncoding
is empty and returns the request body accordingly, considering the immutable configuration.
Line range hint
353-361
:
Improvement: Decoding the body based on encoding.The use of
tryDecodeBodyInOrder
to decode the body based on the encoding is a robust approach. It ensures that the body is correctly decoded and handles errors appropriately. The restoration of the original body if decoding is performed is also a good practice.ctx_test.go (2)
359-367
: LGTM!The
Test_Ctx_BodyRaw
function correctly tests theBodyRaw()
method by setting the request body to a raw byte slice and verifying the output.
387-401
: LGTM!The
Benchmark_Ctx_BodyRaw
function correctly benchmarks theBodyRaw()
method by measuring the time taken to repeatedly call the method and reporting allocations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50
.
Benchmark suite | Current: 70b808f | Previous: fadedcb | Ratio |
---|---|---|---|
Benchmark_Cache_AppendMsgitem - MB/s |
1813.26 MB/s |
961.87 MB/s |
1.89 |
Benchmark_Compress_Levels/Zstd_LevelDefault - B/op |
1 B/op |
0 B/op |
+∞ |
This comment was automatically generated by workflow using github-action-benchmark.
The middleware/cache/manager_msgp_test.go v := item{}
bts := make([]byte, 0, v.Msgsize()) |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3090 +/- ##
==========================================
- Coverage 83.67% 83.60% -0.07%
==========================================
Files 115 115
Lines 8342 8344 +2
==========================================
- Hits 6980 6976 -4
- Misses 1040 1043 +3
- Partials 322 325 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Description
Body()
across all cases by using theContent-Encoding
from the request instead of iterating through all headers.BodyRaw()
.BodyRaw()
.BodyRaw()
.Summary for Body()
Before
After
Benchmark from Branch vs Main
Changes introduced
Type of change