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
Optimize/new route regexp allocations #732
base: main
Are you sure you want to change the base?
Optimize/new route regexp allocations #732
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #732 +/- ##
==========================================
- Coverage 79.58% 78.18% -1.40%
==========================================
Files 5 5
Lines 911 903 -8
==========================================
- Hits 725 706 -19
- Misses 131 141 +10
- Partials 55 56 +1 ☔ View full report in Codecov by Sentry. |
f80a252
to
bd66659
Compare
Rebased off #731 |
bd66659
to
ed62916
Compare
@AlexVulaj thanks for #731 merge; rebased this one for review. Benchmark still the same as in description. |
@coreydaley is there anything i can/should do to get this reviewed? |
// Name or pattern can't be empty. | ||
if name == "" || patt == "" { | ||
return nil, fmt.Errorf("mux: missing name or pattern in %q", | ||
tpl[idxs[i]:end]) | ||
return nil, fmt.Errorf("mux: missing name or pattern in %q", param) |
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.
return nil, fmt.Errorf("mux: missing name or pattern in %q", param) | |
return nil, fmt.Errorf("mux: missing name or pattern in %q", tpl[idxs[i]:end]) |
Having param
as the variable might not help much, as when there's no pattern or name inside braces {}, param will just return an empty string (""), whereas. Above will at least help with the braces for reference.
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.
Gotcha, so {} would be printed as well. Sounds legit, I'll give it a once over and add a test, some inline comments, it's a bit hard to read after some time since writing it
Hi @titpetric, thanks for working on this! |
What type of PR is this? (check all applicable)
Description
This optimizes NewRouter creation. The change introduces strings.Builder for more efficient strings concatenation, and replaces SplitN with Index, avoiding the allocations for the slice.
Related Tickets & Documents
Added/updated tests?
Run verifications and test
make verify
is passingmake test
is passing