onet icon indicating copy to clipboard operation
onet copied to clipboard

efficiency improvements in TCP write

Open jeffallen opened this issue 7 years ago • 0 comments

Adding a MarshalTo function that marshals to an io.Writer would make it possible to have a per-connection output buffer which is reused on each frame write.

sendRaw could reserve 4 bytes at the beginning, and then wrap the rest of the buffer into an io.Writer that would stretch the buffer up to the frame size limit and then start returning errors to tell protobuf to knock it off, if they try to send a struct that is too big. This new "frameWriter" type would have a "finalize()" call that fills the frame length into the first 4 bytes.

sendRaw should be able to operate on average (for structs < 8192 bytes) with no allocs and one write system call. 8192 because the OS can almost always accept a write of 8k without causing a short write and chunking.

As with all performance changes, this needs to be measured.

jeffallen avatar Jan 11 '18 10:01 jeffallen