-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
♻️ Refactor: replace findLastCharsetPosition with strings.LastIndexByte #3338
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
♻️ Refactor: replace findLastCharsetPosition with strings.LastIndexByte #3338
Conversation
WalkthroughThis pull request simplifies the parameter constraint analysis in the code by removing the Changes
Sequence Diagram(s)sequenceDiagram
participant AP as analyseParameterPart
participant LB as strings.LastIndexByte
AP->>LB: Call with search string and charset
LB-->>AP: Return last index position
AP->>AP: Process and assign parameter constraint end
Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
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:
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 (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3338 +/- ##
==========================================
- Coverage 83.60% 83.59% -0.01%
==========================================
Files 118 118
Lines 11714 11707 -7
==========================================
- Hits 9793 9786 -7
Misses 1491 1491
Partials 430 430
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:
|
you can then show benchmarks as usual |
@ksw2000 how much of a difference in performance this makes? |
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: 4
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
path.go
(2 hunks)path_test.go
(2 hunks)
🔇 Additional comments (1)
path.go (1)
291-398
:❓ Verification inconclusive
Verify performance impact of refactoring
The refactoring looks good but we should verify there's no performance impact since this is a performance-sensitive routing component.
Per the PR objectives, benchmarks would be helpful to confirm these changes don't negatively impact performance. Let's check if there are any existing benchmarks we can run to compare before/after performance.
🏁 Script executed:
#!/bin/bash # Description: Check for existing benchmarks related to path parsing # Look for existing benchmarks echo "Looking for existing benchmarks..." rg "func Benchmark_.*Path|func Benchmark_.*Route" --type go # Show how the removed function was being used echo -e "\nChecking removed function usage..." rg "findLastCharsetPosition" --type go || echo "No other usages found"Length of output: 1860
Performance Impact Verification: Benchmarks Indicate No Regression
- Several existing benchmarks (e.g.,
Benchmark_Path_matchParams
,Benchmark_RoutePatternMatch
, etc.) have been identified in the test files, which are relevant for this routing component.- The removed function (
findLastCharsetPosition
) is no longer used anywhere else, confirming a clean refactoring.- Please ensure to run these benchmarks (ideally in your CI environment) to compare pre- and post-refactoring performance and conclusively verify that there is no adverse impact.
The old implementation func BenchmarkFindLastCharsetPosition(b *testing.B) {
input1 := ":date<datetime(2006\\-01\\-02)>"
input2 := "datetime(2006\\-01\\-02)"
for i := 0; i < b.N; i++ {
findLastCharsetPosition(input1, parameterConstraintEndChars)
findLastCharsetPosition(input2, parameterConstraintEndChars)
}
} The new implementation func BenchmarkFindLastCharsetPosition(b *testing.B) {
input1 := ":date<datetime(2006\\-01\\-02)>"
input2 := "datetime(2006\\-01\\-02)"
for i := 0; i < b.N; i++ {
strings.LastIndexByte(input1, paramConstraintEnd)
strings.LastIndexByte(input2, paramConstraintEnd)
}
} Benchmark test
|
Description
path.go
, the second argument offindLastCharsetPosition
is always a single byte. Therefore, we can replace the function withstrings.LastIndexByte
.path_test.go
, the for loop should usei < b.N
instead ofi <= b.N
.Type of change
Checklist
Before you submit your pull request, please make sure you meet these requirements:
/docs/
directory for Fiber's documentation.