♻️ Refactor: use c.app.getString instead of string(...) #2489
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
I noticed 2 functions (those being
GetReqHeaders
andGetRespHeaders
) usestring(...)
instead ofc.app.getString
to convert a byte array to a stringUsing
c.app.getString
is around 16-19% faster, and allocates less. (See benchmark spreadsheets below. Bothc.app.getString
, andstring(...)
was tested on both functions, 100 times.)Benchmark result for using
string(...)
onGetReqHeaders
: GetReqHeaders.xlsx(Average 1,756,668 Iterations, 700 ns/op, 357 B/op, 5 allocs/op)
Benchmark result for using
c.app.getString
onGetReqHeaders
: GetReqHeadersNew.xlsx(Average 2,164,354 Iterations, 567 ns/op, 336 B/op, 2 allocs/op)
Benchmark result for using
string(...)
onGetRespHeaders
: GetRespHeaders.xlsx(Average 1,823,697 Iterations, 678 ns/op, 357 B/op, 5 allocs/op)
Benchmark result for using
c.app.getString
onGetRespHeaders
: GetRespHeadersNew.xlsx(Average 2,176,443 Iterations, 564 ns/op, 336 B/op, 2 allocs/op)
Type of change
Checklist:
Commit formatting:
Use emojis on commit messages so it provides an easy way of identifying the purpose or intention of a commit. Check out the emoji cheatsheet here: https://gitmoji.carloscuesta.me/