Reduce the amount of slicing in GetMemory/GetSpan/Advance by davidfowl · Pull Request #35216 · dotnet/corefx (original) (raw)
- Avoid setting End on the writing segment until commit or until
we're moving to the next segment. - This ends up making the pipe a little bigger but makes writing faster.
PS: This is another take on what I was trying to do with #33948 (inspired by dotnet/aspnetcore#7432)
This is the benchmark https://github.com/aspnet/AspNetCore/blob/c1ce7b9a7764f7ee742da7abb29c1b498f1e2594/src/Servers/Kestrel/perf/Kestrel.Performance/PipeThroughputBenchmark.cs but using the default pool instead of the Kestrel memory pool.
Released version
Method | Mean | Error | StdDev | Median | Op/s | Gen 0/1k Op | Gen 1/1k Op | Gen 2/1k Op | Allocated Memory/Op |
------------------------ |---------:|----------:|----------:|---------:|----------:|------------:|------------:|------------:|--------------------:|
ParseLiveAspNetTwoTasks | 1.002 us | 0.0815 us | 0.2379 us | 1.077 us | 998,447.5 | - | - | - | 1 B |
ParseLiveAspNetInline | 1.113 us | 0.0839 us | 0.2448 us | 1.060 us | 898,460.3 | - | - | - | 24 B |
Before changes
Method | Mean | Error | StdDev | Op/s | Gen 0/1k Op | Gen 1/1k Op | Gen 2/1k Op | Allocated Memory/Op |
------------------------ |-----------:|----------:|---------:|------------:|------------:|------------:|------------:|--------------------:|
ParseLiveAspNetTwoTasks | 951.5 ns | 90.71 ns | 263.2 ns | 1,050,924.4 | - | - | - | 1 B |
ParseLiveAspNetInline | 1,060.2 ns | 109.24 ns | 315.2 ns | 943,226.1 | - | - | - | - |
After changes
Method | Mean | Error | StdDev | Op/s | Gen 0/1k Op | Gen 1/1k Op | Gen 2/1k Op | Allocated Memory/Op |
------------------------ |---------:|---------:|---------:|------------:|------------:|------------:|------------:|--------------------:|
ParseLiveAspNetTwoTasks | 894.1 ns | 87.71 ns | 255.8 ns | 1,118,447.7 | - | - | - | 1 B |
ParseLiveAspNetInline | 991.6 ns | 67.47 ns | 190.3 ns | 1,008,508.4 | - | - | - | - |