0
\$\begingroup\$

I am writing a 2D real-time RPG in C# and I am trying to implement client-server communication using protocol buffers. I am trying to figure out how to implement delta compression to reduce message sizes.

I have read the protobuf "optional" fields take up no extra space on the wire when they are not set (obviously they still do in local memory though), so if I can just programmatically determine my deltas efficiently I would be in better shape.

Here's the problem. I can think of a few ways, but none seem to be ideal. I was wondering if someone could point me in the right direction.

  1. Try to keep a dirty bit array for EACH message-able class that gets cleared when a message is sent and marked when a variable changes. Then to send a message you just send the members that match the Boolean fields. This has LOW maintainability, but probably decent performance.

  2. Every message-able class keeps a "pastMessage" member that gets updated saved when a message is sent. Then just serialize your current state and diff the two messages. This would probably have LOW performance and almost DOUBLE memory overhead for the game types..

  3. Create a new message every time a message was sent and "fill-in-as-you-go." This would provide a better performance than the above, but still would essentially double my memory overhead on my server.

Any other ideas?

\$\endgroup\$
3
\$\begingroup\$

Start with whatever's easiest to get your stuff up and working. It sounds like you have a good grasp of potential improvements and tradeoffs, so, go for "easy and works" first, and improve if needed. Do profiling of time & space. Might even, just to start, send un-delta'd messages, if it is feasible.

Choice 1 is pretty good, by the way, and there may be ways to lower the maintenance burden, with c# property tricks. Or at least to enforce a test suite that will alert you if you add a field that doesn't have the Boolean-on-change nature correctly implemented, by reflecting over members or similar...

\$\endgroup\$
  • \$\begingroup\$ Thanks! I have already gotten whole messages sent, but I've been reading that delta compression is essentially necessary. So I was trying to puzzle it out. I guess I'll aim for option 1 then! \$\endgroup\$ – guitar80 Jan 9 '15 at 1:27
  • \$\begingroup\$ There may be some opportunities to streamline the "Match boolean field" part, like adding them to a list when they're first set. Or using a 64-bit int for mask-checking... \$\endgroup\$ – david van brink Jan 9 '15 at 5:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.