simple-binary-encoding icon indicating copy to clipboard operation
simple-binary-encoding copied to clipboard

[Go] no zero-copy?

Open asido opened this issue 5 years ago • 5 comments

I generated Go code and see there is no Wrap() method. Instead, there is Encode(io.Reader), which fetches and assigns all values to public fields in the model. Is there no zero-copy alternative in Go, that allows to read the data in-place?

asido avatar Mar 19 '20 00:03 asido

This is correct. The current Go implementation takes raw SBE message and creates a fully-formed Golang struct from it and thus every field is marshaled.

The reasoning behind this is described here: https://github.com/real-logic/simple-binary-encoding/wiki/Golang-User-Guide#golang-idioms

This design prioritizes easy-to-use and hard-to-misuse over performance. It should be possible to make a zero-copy / flyweight generator if someone were up to the task.

neomantra avatar May 28 '21 10:05 neomantra

@ethanf curious if your impl ended up looking promising?

matthewdowney avatar Jul 01 '23 23:07 matthewdowney

@ethanf curious if your impl ended up looking promising?

I've updated https://github.com/ethanf/simple-binary-encoding/tree/go-flyweight with the latest code. It's code complete and mostly works, but there's still work to do updating the tests unfortunately.

ethanf avatar Jul 03 '23 09:07 ethanf

https://github.com/ethanf/simple-binary-encoding/tree/go-flyweight has passing tests now, does anyone have a preference for how to switch between the flyweight and struct versions of the generated code? Is a system property that switches between the generators acceptable?

ethanf avatar Aug 07 '23 21:08 ethanf

Thanks for your contribution! I only started looking at it and will take it for a spin in a few weeks.

I do think that using system properties like that is consistent with other SBE / Aeron tool options.

neomantra avatar Aug 11 '23 14:08 neomantra