MessagePack tons of garbage

allencook200

Member
Joined
Apr 27, 2021
Messages
9
Programming Experience
1-3
So I'm writing an online game using MessagePack and around every 20ms the server sends about 500 entities all serialized into a single object, to every client. No problem, except that every time it deserializes on each client, it seems like it creates 500 new objects, which is really killing my client's game when garbage collection hits.



That popup window showing "GC.Alloc" is only one GC allocation event. If you look closely, there's multiple red boxes that the profiler isn't showing data for. Literal tons of garbage.

JsonReceive = MessagePackSerializer.Deserialize<Json_ClientTickUpdate>(Message);

And here's the command that I'm running, once every around 20ms. If I get rid of that single line, the game runs fine. Surely there's a way to keep messagepack from creating so much garbage?
 
Perhaps there's a way to reuse the object instead of constantly making a new one and marking it for deletion? I really have no idea. Hoping someone knows.
 
What does the documentation for that serialization package say about customizing object instantiation?
 
What does the documentation for that serialization package say about customizing object instantiation?
I don't really know to be honest. I searched around on the github for issues and found that other people had the same issue. The dev said that he was going to add a feature to allow people to deserialize into existing objects instead of instantiating a new one. But that was in like September. I'm just sort of wondering if there's any possible workaround.
 
In your shoes, I would either
- fork the code and start writing in my own support for object reuse; OR
- assign object IDs to all my objects, and then serialize only the object IDs as a single list or array; OR
- redesign things so that only objects relative within a smaller scope/volume are sent -- this is what most MMORPGs do: they don't send everything happening in the world to everybody else. They only send what is happening relatively close to the player.

500 Int64's in a single array object should have less memory impact than 500 separate objects.
 
Back
Top Bottom