Allocation-free version of Send/Receive
Closed this issue · 6 comments
hey joel,
would you be up for having allocation-free Send/Receive options on the websockets? what do you think of the following:
for send:
the internal function is taking an ArraySegment. in our scenario it would come handy if we could just provide that instead of copying to an array first.
for receive:
same here, the internal function is returning an ArraySegment of which currently two copies are made: first into a MemoryStream, then into the buffer (which is also currently allocated twice: L607 and L614). returning an ArraySegment should allow you to get rid of all of this, right?
same is also applicable to the server.
Hi @joreg for sure! Anything that makes the library more efficient :) Do you have a PR handy by chance?
great! no PR handy, but if you prefer, i can attempt one.
ok, here is the first part, for sending: #91
this should be a non-breaking change.
for the receiving part i'm afraid this would be a minor breaking change, since the MessageReceivedEventArgs will need to have ArraySegment of byte instead of byte[] for data. would you still be accepting this? (i'd PR the same for SuperSimpleTCP then which has the same issue)
Really appreciate you putting this together @joreg - I updated the PR with the NuGet link and the commit. Thanks!
thanks for the quick merge.
and again re the same issue for the receiver. how do you think about a breaking change there as i outlined above?