-
-
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
⚡️ perf(ctx.Range): reduce allocations #2705
Conversation
thanks for the optimization unfortunately we can't do it like this maybe you can do the exchange of the cut function only for the golang version from 1.18 ? here an example |
Or we can use strings.Index instead of strings.Cut. It might worth for performance gain on 1.17 |
ok sure, lets test this |
Sure, I'll try out strings.IndexByte |
ctx_test.go
Outdated
c := app.AcquireCtx(&fasthttp.RequestCtx{}) | ||
defer app.ReleaseCtx(c) | ||
|
||
james := []struct { |
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.
oops...I'll fix this too...
|
@nickajacks1 any progress? |
Yes, sorry, been busy. Just need to find time to sit down and finish this. Should be ready within the next couple days. |
strings.Split was causing extra allocations where using strings.IndexByte can suffice. ALso switch from strconv.Atoi because it causes an allocation when parsing a non-integer, which is common for Ranges.
533fb90
to
ff29a15
Compare
Removed strings.Cut, added more tests, updated Benchmark to include a case with multiple ranges.
|
Description
strings.Split
was causing extra allocations wherestrings.Cut
can suffice. Also switch fromstrconv.Atoi
because it causes an allocation when parsing a non-integer, which is common for Ranges.The remaining allocation (see benchmarks) comes from the returned slice.
Checklist:
Bench: