Skip to content

Commit ee0e4c4

Browse files
perf: optimize JSON deserialization from stream
Replaced `StreamReader.ReadToEnd()` and string-based deserialization with direct stream deserialization in `SystemTextJsonSerializer.Deserialize<T>(Stream)`. This change avoids an intermediate string allocation for the entire JSON payload, reducing memory pressure and improving performance, especially for larger responses. The stream disposal logic is maintained using the `using (stream)` pattern. Co-authored-by: antarr <974295+antarr@users.noreply.github.com>
1 parent 84cd802 commit ee0e4c4

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

Withings.NET/Client/Authenticator.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,9 @@ public T Deserialize<T>(string s)
124124

125125
public T Deserialize<T>(Stream stream)
126126
{
127-
using (var reader = new StreamReader(stream))
127+
using (stream)
128128
{
129-
var text = reader.ReadToEnd();
130-
return JsonSerializer.Deserialize<T>(text, _options);
129+
return JsonSerializer.Deserialize<T>(stream, _options);
131130
}
132131
}
133132

0 commit comments

Comments
 (0)