Skip to content
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

Benchmarks and Improvements for parseRequestURL function #711

Merged
merged 8 commits into from
Oct 2, 2023

Commits on Oct 2, 2023

  1. Benchmarks for applying PathParams in parseRequestURL function

    ```shell
    % go test -benchmem -bench=. -run=^Benchmark
    goos: darwin
    goarch: amd64
    pkg: github.com/go-resty/resty/v2
    cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Benchmark_parseRequestURL_PathParams-16           524658              2260 ns/op             448 B/op          9 allocs/op
    PASS
    ok      github.com/go-resty/resty/v2    2.327s
    ```
    SVilgelm committed Oct 2, 2023
    Configuration menu
    Copy the full SHA
    250ef4b View commit details
    Browse the repository at this point in the history
  2. Benchmarks for applying QueryParams in parseRequestURL function

    ```shell
    % go test -benchmem -bench=. -run=^Benchmark
    goos: darwin
    goarch: amd64
    pkg: github.com/go-resty/resty/v2
    cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Benchmark_parseRequestURL_QueryParams-16          865923              1371 ns/op             416 B/op         13 allocs/op
    PASS
    ok      github.com/go-resty/resty/v2    2.491s
    ```
    SVilgelm committed Oct 2, 2023
    Configuration menu
    Copy the full SHA
    49dafe4 View commit details
    Browse the repository at this point in the history
  3. improve the performance of applying the path parameters

    * Use the map to collect all replacements and use replace all path parameters using O(1) logic
    * Add additional unit tests to cover empty `{}` and not closed `{bar` path parameters
    
    ```shell
    % go test -benchmem -bench=. -run=^Benchmark
    goos: darwin
    goarch: amd64
    pkg: github.com/go-resty/resty/v2
    cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Benchmark_parseRequestURL_PathParams-16           785971              1410 ns/op             320 B/op          6 allocs/op
    PASS
    ok      github.com/go-resty/resty/v2    1.445s
    ```
    SVilgelm committed Oct 2, 2023
    Configuration menu
    Copy the full SHA
    a838676 View commit details
    Browse the repository at this point in the history
  4. improve the performance of applying the query parameters

    * improve the loging by adding the query parameters from the request first, then adding the parameters from the client and skip if already exists
    * additional unit tests for the query parameters
    
    ```shell
    % go test -benchmem -bench=. -run=^Benchmark
    goos: darwin
    goarch: amd64
    pkg: github.com/go-resty/resty/v2
    cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Benchmark_parseRequestURL_QueryParams-16         1000000              1158 ns/op             352 B/op          9 allocs/op
    PASS
    ok      github.com/go-resty/resty/v2    2.473s
    ```
    SVilgelm committed Oct 2, 2023
    Configuration menu
    Copy the full SHA
    05530d3 View commit details
    Browse the repository at this point in the history
  5. using acquireBuffer

    reusing a buffer from the pool decreases the allocs and memory usage
    
    ```shell
    % go test -benchmem -bench=. -run=^Benchmark
    goos: darwin
    goarch: amd64
    pkg: github.com/go-resty/resty/v2
    cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Benchmark_parseRequestURL_PathParams-16           753834              1367 ns/op             256 B/op          5 allocs/op
    Benchmark_parseRequestURL_QueryParams-16         1000000              1167 ns/op             352 B/op          9 allocs/op
    PASS
    ok      github.com/go-resty/resty/v2    2.373s
    ```
    SVilgelm committed Oct 2, 2023
    Configuration menu
    Copy the full SHA
    2566142 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    f065f0c View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    40fde0a View commit details
    Browse the repository at this point in the history
  8. remove unneeded if

    SVilgelm committed Oct 2, 2023
    Configuration menu
    Copy the full SHA
    402986b View commit details
    Browse the repository at this point in the history