online-fps icon indicating copy to clipboard operation
online-fps copied to clipboard

Don't copy state when sending message

Open randomPoison opened this issue 8 years ago • 1 comments

Currently, Serialized requires the message being sent be owned data, which requires that we make a copy of any game state in order to send it as part of a message. In the case where there is a lot of data to be sent (e.g. the entire world state when a client joins), this requires making a temporary copy of a lot of data, including potentially making multiple short-lived allocations.

This shouldn't be necessary, as the message gets serialized to a buffer almost immediately anyway. We should update the interface to Serialized (or any other message sending mechanism in sumi) to take a reference to the message being sent. It should immediately serialize the message into a buffer, removing the need to ever take ownership of the message being sent, and thereby removing the need to make a copy of any world state when sending it in a message.

randomPoison avatar Dec 22 '17 16:12 randomPoison

For now, this work is as simple as changing the Sink impl for Serialized to take a reference to the message being sent, rather than taking the message by value. Depending on what changes I make to sumi, this may change. In that case, I'll try to update this ticket accordingly.

randomPoison avatar Dec 22 '17 17:12 randomPoison