6 ms·
If you don't have better ideas for improving your packet size at least push your JSON through msgpack. Using strings as keys (properties) is ultra bad for your
by rezoner 7y ago
If you don't have better ideas for improving your packet size at least push your JSON through msgpack. Using strings as keys (properties) is ultra bad for your bandwidth too. In general JSON is only suitable for turn based games.
- nickyvanurk 7y agoThanks for pointing this out. This will be my next improvement.
- rezoner 7y agops: Don't use the official implementation - it is slow. Go with one of the lite projects like that one https://github.com/kawanet/msgpack-lite https://github.com/kawanet/msgpack-lite
- nickyvanurk 7y agoMuch appreciated!
- echelon 7y agoProtobuf would be an excellent serialization. It's compact, binary, and efficient. There's a ton of library support in nearly every language imaginable.
- arendtio 7y agoI am not 100% sure, but I think I read somewhere (at least 2 years ago), that browsers are actually faster using JSON than Protobuf (a bit counter-intuitive). Nevertheless, bandwidth-wise it could make sense anyway, but I think it makes sense to consult some benchmarks in this case.
- redka 7y agoFor my games[1] I use a custom binary protocol which is not that difficult to pull off. Actually building a buffer with JavaScript's DataView[2] and ArrayBuffers produces very compact results since you're free to optimize the packets for each specific game - for example a single uInt8 can store 8 different flags for a game character - things like dead/alive, up/down, right/left, walking/running, etc. [1] https://redka.games https://redka.games [2] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- stcredzero 7y agoIf you don't have better ideas for improving your packet size at least push your JSON through msgpack. I'm about to change over to msgpack for my own multiplayer real time browser game. I'd use protobuf, but the extra code generation step would get in the way of my plans to turn my MMO into an MMO-game-as-lambdas PaaS project. Right now, I'm using my own protocol which uses something somewhat like base-85 for encoding, except it's base-92. It's a binary packing format, but packs directly into base-92 encoding. This packed base-92 is encapsulated into JSON, which minimizes the use of keys. This might all sound horrible, but I'm able to achieve what Flatpack achieves: no copies are needed to extract the data. That, and the remaining slight JSON overhead makes it easier to debug network traffic.
- deleted 7y ago[deleted]