80O / PlusEMU

39 stars 26 forks source link

Reduce memory fragmentation in packet handling #25

Closed 80O closed 2 years ago

80O commented 2 years ago

Currently every packet that is received is copied to a new byte array. Doing this will cause a lot of memory fragmentation in the long run.

To resolve this issue we can use the following features:

ArrayPool\<byte>.Shared
Using the arraypool, arrays can temporarily be borrowed. ReadOnlySpan\<byte>
Using read only spans, no copies of the packet buffer needs to be created. We can use this to convert to and from byte[] to int.

80O commented 2 years ago

Implemented during Nitro implementation.