-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Optimize Pipe.DefaultPipeWriter GetSpan and Advance #29837
Conversation
} | ||
|
||
// Slice the AvailableMemory to the WritableBytes size | ||
int end = _writingHead.End; | ||
Memory<byte> availableMemory = _writingHead.AvailableMemory; | ||
availableMemory = availableMemory.Slice(end, availableMemory.Length - end); | ||
Span<byte> availableMemory = _writingHead.AvailableMemory.Span; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: availableMemory
=> availableSpan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use _writingHead
outside the lock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was used previously outside lock?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good time to stop :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or wait, it's not supposed to be syncronised.
Any perf numbers? |
I don't know of any relevant benchmarks that exist today that will help with this (at this scale). Any ideas which ones to run and compare? Nano benchmarks, measuring each of the methods in isolation show small improvements (~10%). BenchmarkDotNet=v0.10.14, OS=Windows 10.0.16299.431 (1709/FallCreatorsUpdate/Redstone3)
Intel Xeon CPU E5-1620 v2 3.70GHz, 1 CPU, 8 logical and 4 physical cores
Frequency=3604598 Hz, Resolution=277.4234 ns, Timer=TSC
.NET Core SDK=2.1.300-rtm-008866
[Host] : .NET Core 2.1.0-rtm-26516-03 (CoreCLR 4.6.26516.03, CoreFX 4.6.26516.03), 64bit RyuJIT
DefaultJob : .NET Core 2.1.0-rtm-26516-03 (CoreCLR 4.6.26516.03, CoreFX 4.6.26516.03), 64bit RyuJIT If marked with AggressiveInlining attribute:
If not inlined:
|
) * Optimize DefaultPipeWriter GetSpan * Some code refactoring and additional optimizations * Remove unnecessary length calculation when slicing memory. * Address PR feedback. Commit migrated from dotnet/corefx@f189356
cc @pakrym, @davidfowl, @benaadams