-
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
Udp Socket.ReceiveFrom a lot of allocations for IPAdress #30196
Comments
ReceiveFrom variants have a surprisingly large number of allocations right now. This is likely to have a significant impact on QUIC. Seems worth a look at what we can do to improve things. |
What do you think of adding some APIs to use class Socket
{
public int SendTo(ReadOnlySpan<byte> buffer, SocketFlags socketFlags, SocketAddress remoteAddress);
public ValueTask<int> SendToAsync(ReadOnlyMemory<byte> buffer, SocketFlags socketFlags, SocketAddress remoteAddress);
public int ReceiveFrom(Span<byte> buffer, SocketFlags socketFlags, SocketAddress remoteAddress);
public ValueTask<int> ReceiveFromAsync(Memory<byte> buffer, SocketFlags socketFlags, SocketAddress remoteAddress);
} As well as some changes to conveniently access the result: class SocketAddress
{
public ReadOnlyMemory<byte> IPAddress { get; }
public int Port { get; }
} |
Looking amazing. It would solve my problem. |
Duplicate of dotnet/corefx#40933 |
At production server, I have a simple code
I call this code every millisecond. Recently I found out that almost 40% of allocations from my application are from this code. And all of the allocations are only 3 primitives: SocketAddress, IPEndPoint, IPAdress. It seems wasteful. Maybe I do something wrong? Can I read data from the UDP socket without this allocations? Can I have managed UDP transport with zero allocations?
Simple reproduction https://github.com/kripergvg/UdpAllocations
dotmemory after 4 minutes
The text was updated successfully, but these errors were encountered: