Closed SVilgelm closed 11 months ago
All modified lines are covered by tests :white_check_mark:
Comparison is base (
4604150
) 96.57% compared to head (402986b
) 96.62%.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
@jeevatkm I hope this improvement will help the users. The change is relatively huge, it would be great if you can run some additional tests, or I can add additional tests
@jeevatkm I hope this improvement will help the users. The change is relatively huge, it would be great if you can run some additional tests, or I can add additional tests
Thanks, @SVilgelm; I agree this improvement needs good testing. I will let you know!
rebased
goos: darwin
goarch: amd64
pkg: github.com/go-resty/resty/v2
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
│ old.txt │ new.txt │
│ sec/op │ sec/op vs base │
_parseRequestHeader-16 190.2n ± 3% 191.3n ± 2% ~ (p=0.306 n=10)
_parseRequestURL_PathParams-16 1.570µ ± 1% 1.290µ ± 1% -17.83% (p=0.000 n=10)
_parseRequestURL_QueryParams-16 1.347µ ± 1% 1.109µ ± 1% -17.68% (p=0.000 n=10)
geomean 738.1n 649.2n -12.04%
│ old.txt │ new.txt │
│ B/op │ B/op vs base │
_parseRequestHeader-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
_parseRequestURL_PathParams-16 448.0 ± 0% 256.0 ± 0% -42.86% (p=0.000 n=10)
_parseRequestURL_QueryParams-16 416.0 ± 0% 352.0 ± 0% -15.38% (p=0.000 n=10)
geomean ² -21.51% ²
¹ all samples are equal
² summaries must be >0 to compute geomean
│ old.txt │ new.txt │
│ allocs/op │ allocs/op vs base │
_parseRequestHeader-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
_parseRequestURL_PathParams-16 9.000 ± 0% 5.000 ± 0% -44.44% (p=0.000 n=10)
_parseRequestURL_QueryParams-16 13.000 ± 0% 9.000 ± 0% -30.77% (p=0.000 n=10)
geomean ² -27.28% ²
¹ all samples are equal
² summaries must be >0 to compute geomean
sure, I'll check later today, biking 🚴 around
sure, I'll check later today, biking 🚴 around
Thanks, take your time 👍 safe biking!
New benchmarks, almost no changes
goos: darwin
goarch: amd64
pkg: github.com/go-resty/resty/v2
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
│ old.txt │ new.txt │
│ sec/op │ sec/op vs base │
_parseRequestHeader-16 189.1n ± 3% 188.7n ± 2% ~ (p=0.361 n=10)
_parseRequestURL_PathParams-16 1.564µ ± 0% 1.304µ ± 1% -16.62% (p=0.000 n=10)
_parseRequestURL_QueryParams-16 1347.5n ± 1% 971.0n ± 2% -27.94% (p=0.000 n=10)
geomean 735.8n 620.5n -15.68%
│ old.txt │ new.txt │
│ B/op │ B/op vs base │
_parseRequestHeader-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
_parseRequestURL_PathParams-16 448.0 ± 0% 256.0 ± 0% -42.86% (p=0.000 n=10)
_parseRequestURL_QueryParams-16 416.0 ± 0% 352.0 ± 0% -15.38% (p=0.000 n=10)
geomean ² -21.51% ²
¹ all samples are equal
² summaries must be >0 to compute geomean
│ old.txt │ new.txt │
│ allocs/op │ allocs/op vs base │
_parseRequestHeader-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
_parseRequestURL_PathParams-16 9.000 ± 0% 5.000 ± 0% -44.44% (p=0.000 n=10)
_parseRequestURL_QueryParams-16 13.000 ± 0% 9.000 ± 0% -30.77% (p=0.000 n=10)
geomean ² -27.28% ²
¹ all samples are equal
² summaries must be >0 to compute geomean
goos: darwin
goarch: amd64
pkg: github.com/go-resty/resty/v2
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
│ old.txt │ new.txt │
│ sec/op │ sec/op vs base │
_parseRequestURL_PathParams-16 1.570µ ± 1% 1.269µ ± 1% -19.15% (p=0.000 n=10)
_parseRequestURL_QueryParams-16 1343.5n ± 2% 999.3n ± 4% -25.62% (p=0.000 n=10)
geomean 1.452µ 1.126µ -22.45%
│ old.txt │ new.txt │
│ B/op │ B/op vs base │
_parseRequestURL_PathParams-16 448.0 ± 0% 256.0 ± 0% -42.86% (p=0.000 n=10)
_parseRequestURL_QueryParams-16 416.0 ± 0% 352.0 ± 0% -15.38% (p=0.000 n=10)
geomean 431.7 300.2 -30.46%
│ old.txt │ new.txt │
│ allocs/op │ allocs/op vs base │
_parseRequestURL_PathParams-16 9.000 ± 0% 5.000 ± 0% -44.44% (p=0.000 n=10)
_parseRequestURL_QueryParams-16 13.000 ± 0% 9.000 ± 0% -30.77% (p=0.000 n=10)
geomean 10.82 6.708 -37.98%
The benchmarks for the applying PathParams and adding QueryParams.
Original results:
After the improvements:
The applying of PathParams has been improved by using O(1) logic instead of O(N). (N the number of PathParams + RawPathParams in both client and request). Instead of calling
strings.Replace
for each path parameter, the current logic collects all needed parameters in a map then replaces all parameters in URL by searching for the curly brackets and replacing. It scans the whole URL just once, from first to last positions.The improvements of adding the QueryParams have been done by swapping the processing order. First - process the request's QueryParams, only then process the client's QueryParams and skip already existed instead of deleting.