Skip to content

Reader/Writer encoding interfaces

Luke Champine requested to merge marshal into master

MarshalSia and UnmarshalSia now take an io.Writer and io.Reader, respectively. This makes them better aligned with Encode and Decode. More importantly, it removes the need for all manually-marshaled data to be prefaced with a length prefix. This allows us to start writing MarshalSia methods for types where speed is important, e.g. types.Block (implemented here). Previously, doing so would have broken compatibility due to the length prefix.

After implementing (Un)MarshalSia methods for types.Block, non-rigorous benchmarking reveals the following speedups when encoding and decoding an empty block:

Encode benchmark: 38.70 MB/s -> 47.87 MB/s (23.7% faster)
Decode benchmark: 41.69 MB/s -> 55.80 MB/s (33.9% faster)

I suspect this speedup will only be magnified when we start manually marshaling transactions, and will be more noticeable with blocks that contain real data.

Merge request reports