Shrinking the Update Messages

I think my biggest problem right now is that the messages being passed between the server and clients for game updates are way too large. The good news is, there is a lot I can do to improve the situation.

Don’t send the updates for the objects that I don’t really need to keep in sync

For example, the particles that the players see for an explosion are completely cosmetic. So if they appear different on different machines it does not really matter. I tried this before and it didn’t work. But I think the problem was that I was removing the particles from the message before sending out to the clients. Which is fine. But then on the clients I was over writing the game state with the one from the server. Which effectively meant that there were no more explosions. At all! So the key this time will be to remove them from the updates but keep them on the client. I think I can do this by retaining the client state and just removing the objects that I AM sending down from the server.

Don’t send the default JSON

Right now I just send the collection of objects down which get sent as JSON. The resulting JSON is very verbose. Every field is named. Great for human readability but in this case we know the data structure that is coming so we can get rid of all that! So, I’ll have to write a serializer that build and array of arrays. The inner array be comprised of the values for each object.

Don’t send down floating point values

Right now a lot of each message is being taking up by long floating point numbers. And canvas performance degrades with floating point numbers anyway. So should round all of the numbers to integers when I serialize. I think that will also save a ton of bandwidth.

That should be a good start anyway. I know you can go a lot deeper by further serializing the messages to different encodings, using compression, etc. Baby steps!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s