rdavisau / sockets-for-pcl

Cross-platform socket API for Xamarin iOS/Android/Forms, Xamarin.Mac/MonoMac, Windows Phone 8/8.1, Windows Store and Windows Desktop.
MIT License
224 stars 72 forks source link

Garbage pressure not optimal #114

Closed ThomasZeman closed 6 years ago

ThomasZeman commented 7 years ago

Hi!

I am playing around with sockets-for-pcl a bit and have noticed that the garbage pressure generated by the library could be improved:

In UpdSocketBase (Android) 2 strings are created for every incoming datagram:

var remoteAddress = msg.RemoteEndPoint.Address.ToString(); var remotePort = msg.RemoteEndPoint.Port.ToString();

That is not ideal when for example developing a multi-player game with a send-rate of 30 or 60fps.

I am aware of that IPEndPoint is not available in PCLs so therefore it might be a good idea to introduce an abstraction for that (also concerning IPv6). It could come from a Dictionary which in turn has an IPEndPoint as its key. RemoteEndPoint.GetHashCode() should be fast enough.

Also, there is a small asymmetry between receiving and sending datagrams: ports are converted to strings but SendTo* wants an int for sending.

Thomas

rdavisau commented 7 years ago

Hi! Thanks for reviewing and for the good observations. I like the idea of keying to an IPEndPoint abstraction. I would take a PR a for a more pressure-friendly solution if you are interested in contributing.

From memory, the asymmetry you refer to was due to the fact the the WinRT implementation of UDP gives port back as a string and I wasn't ready to risk a bona-fide string coming back. I suppose it must not be possible though; even the documentation suggests that despite being a string, it returns the UDP port number.

ThomasZeman commented 7 years ago

Yes sure. At the moment I dont have the full Xamarin environment running so I cannot offer a PR but maybe in the next couple of weeks!

ThomasZeman commented 7 years ago

Hi there again! I've started writing my own cross platform socket library which fits better to my needs. Its functionality is similiar to the Lidgren3 library but as a PCL and cross platform. That means I won't have time to contribute to sockets-for-pcl. If you want to please just close this issue.