akamsteeg / AtleX.HaveIBeenPwned

A modern, fully async, high performance, .NET client library for the API of HaveIBeenPwned.com
https://www.nuget.org/packages/AtleX.HaveIBeenPwned/
MIT License
5 stars 0 forks source link

In HaveIBeenPwnedClient.GetBreachesInternalAsync(string, BreachMode, CancellationToken), a new UriBuilder is always created even if we don't need one #44

Closed akamsteeg closed 4 years ago

akamsteeg commented 4 years ago

In HaveIBeenPwnedClient.GetBreachesInternalAsync(string, BreachMode, CancellationToken), a new UriBuilder is always created:

https://github.com/akamsteeg/AtleX.HaveIBeenPwned/blob/f51d5ab5bb9a675ab09b156e7c24fc233d724542/src/AtleX.HaveIBeenPwned/HaveIBeenPwnedClient.cs#L273-L286

But we only need that UriBuilder when the BreachMode is BreachMode.ExcludeUnverified or (currently) BreachMode.All. Otherwise just a Uri is enough. A UriBuilder is quite expensive in both time and memory so removing it from the default path would be nice.

akamsteeg commented 4 years ago

Fixed in 9254148dedb5b81cd71d9578422901e3990cff05

Results

Before:

|                      Method |     Toolchain |       Mean |      Error |     StdDev | Ratio | RatioSD |   Gen 0 |  Gen 1 | Gen 2 | Allocated |
|---------------------------- |-------------- |-----------:|-----------:|-----------:|------:|--------:|--------:|-------:|------:|----------:|
| GetBreachesAsync_BreachMode | .NET Core 2.1 |  10.658 us |  13.374 us |  0.7331 us |  1.00 |    0.00 |  0.9155 |      - |     - |   4.27 KB |
| GetBreachesAsync_BreachMode | .NET Core 3.1 |   9.075 us |  21.242 us |  1.1643 us |  0.85 |    0.11 |  0.8698 |      - |     - |   4.02 KB |
| GetBreachesAsync_BreachMode |        net472 |  15.273 us |  14.411 us |  0.7899 us |  1.44 |    0.14 |  1.2360 |      - |     - |   5.73 KB |

After:

|                      Method |     Toolchain |       Mean |        Error |      StdDev | Ratio | RatioSD |   Gen 0 |  Gen 1 | Gen 2 | Allocated |
|---------------------------- |-------------- |-----------:|-------------:|------------:|------:|--------:|--------:|-------:|------:|----------:|
| GetBreachesAsync_BreachMode | .NET Core 2.1 |   7.796 μs |     1.233 μs |   0.0676 μs |  1.00 |    0.00 |  0.7324 |      - |     - |   3.39 KB |
| GetBreachesAsync_BreachMode | .NET Core 3.1 |   5.639 μs |     7.193 μs |   0.3943 μs |  0.72 |    0.05 |  0.6866 |      - |     - |   3.16 KB |
| GetBreachesAsync_BreachMode |        net472 |  12.053 μs |     2.363 μs |   0.1295 μs |  1.55 |    0.03 |  0.9766 |      - |     - |   4.53 KB |