Closed akamsteeg closed 5 years ago
In HaveIBeenPwnedClient.GetAsync(HttpRequestMessage, CancellationToken), a new MemoryStream is created for every request.
HaveIBeenPwnedClient.GetAsync(HttpRequestMessage, CancellationToken)
MemoryStream
https://github.com/akamsteeg/AtleX.HaveIBeenPwned/blob/88c3561bbe0d60aa5cdd5f877c953b18181b4d7d/src/AtleX.HaveIBeenPwned/HaveIBeenPwnedClient.cs#L535..L570
We can avoid the copy of the response stream to the MemoryStream by just returning the output HttpResponseMesssage and parse the content Stream directly,
HttpResponseMesssage
Stream
Before:
BenchmarkDotNet=v0.11.5, OS=Windows 10.0.18362 Intel Core i7-8850H CPU 2.60GHz (Coffee Lake), 1 CPU, 12 logical and 6 physical cores .NET Core SDK=3.0.100 [Host] : .NET Core 2.1.13 (CoreCLR 4.6.28008.01, CoreFX 4.6.28008.01), 64bit RyuJIT ShortRun : .NET Core 2.1.13 (CoreCLR 4.6.28008.01, CoreFX 4.6.28008.01), 64bit RyuJIT Job=ShortRun IterationCount=3 LaunchCount=1 WarmupCount=3
After:
Fixed in 4e71017d and 546117b9.
In
HaveIBeenPwnedClient.GetAsync(HttpRequestMessage, CancellationToken)
, a newMemoryStream
is created for every request.https://github.com/akamsteeg/AtleX.HaveIBeenPwned/blob/88c3561bbe0d60aa5cdd5f877c953b18181b4d7d/src/AtleX.HaveIBeenPwned/HaveIBeenPwnedClient.cs#L535..L570
We can avoid the copy of the response stream to the
MemoryStream
by just returning the outputHttpResponseMesssage
and parse the contentStream
directly,Before:
After: