CSharpPerformanceBoosters icon indicating copy to clipboard operation
CSharpPerformanceBoosters copied to clipboard

Extra string allocation can be removed

Open Husqvik opened this issue 3 years ago • 0 comments

at line if (DateTime.TryParse(Encoding.UTF8.GetString(line[..comaAt]), out var doj))

Encoding.UTF8.GetString allocates string on heap which is unnecessary, can be replaced by Encoding.UTF8.GetChars writing chars into Span<char> that can be allocated on stack. Saves additional 4 MB allocations in the benchmark.

Husqvik avatar Jun 12 '21 18:06 Husqvik