-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
avoid allocating SocketAddress GCHandle for every ReceiveFromAsync #89808
Conversation
Tagging subscribers to this area: @dotnet/ncl Issue Detailsfixes #86513 Because we always serialize runtime/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEventArgs.Windows.cs Lines 863 to 864 in f60757a
So we and up creating Perftests do not really show much because they do not track the GCHandles.
|
src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEventArgs.Windows.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEventArgs.Windows.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEventArgs.Windows.cs
Outdated
Show resolved
Hide resolved
I updated names and comments @stephentoub |
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.
LGTM
Did you happen to measure any impact to just allocating and freeing on each operation? Would that clean up any code / make the SAEA smaller?
no, but it would be easy to try. My guess is that the impact would be small - in perf tests even voiding GCHandle was small -> most benefit come from memory management IMHO |
fixes #86513
contributes to #30797
Because we always serialize
EndPoint
toSocketAddress
this check is never true:runtime/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEventArgs.Windows.cs
Lines 863 to 864 in f60757a
So we and up creating
GCHandle
for every packet making all the logic useless.The fix I discussed with @stephentoub is to use
NativeMemory
that is quite fast and same memory chunk can persist across many recipes regardless of the actuallySocketAddress
.As downside we need to copy the actual socket address bytes - but it is small so it should be fast and it does not got memory with movable blocks.
Perftests do not really show much because they do not track the GCHandles.