GlaireDaggers / Netcode.IO.NET

A pure managed C# implementation of the Netcode.IO spec
MIT License
255 stars 47 forks source link

ByteArrayReaderWriter allocating a lot of memory #11

Open void050 opened 7 years ago

void050 commented 7 years ago

Hello Alan! Thanks for your work) Sorry for my english(

Call a WriteBuffer for an array[2048] allocate 10.5 kb memory. So when i tryied to send a message to a client every client.SendPayload allocated about 30 kb, 30 kb 30 times/second 100 players = 87 mb per second.

After changing ByteArrayReaderWriter to Array.copy and creating a broadcast method for a client allocating 1.7 kb or 3.7 kb(idk why, packets is identical). But it still allocating 8 mb per second. Unity3d 2017, memory check in profiler

void050 commented 7 years ago

Unfortunately 1 kb allocated in AEAD_Chacha20_Poly1305.Encrypt

GlaireDaggers commented 7 years ago

You are correct - I've already noticed the allocations happening within BouncyCastle and resolved them, have just been too busy to actually upload them. A push to fix this should be available today. Based on my profiling, it should eliminate all but one allocation (and that one remaining allocation is in Socket.SendTo and cannot be fixed)