It took me a long time to realize that marshal/unmarshal functions should not operate on streams. You're just translating to/from an object in memory anyway, so the unbounded nature of streams doesn't buy you anything.
Marshalling into a buffer, on the other hand, allows for crucial optimizations like reusing memory. The real kicker, at least in Go, is that writing to an io.Writer forces a heap allocation. Marshalling is definitely an area where you want to aim for zero allocations.
-
-
Buffers are also nice for unmarshalling, because they force you to frame your messages with their size; consequently, you'll know up front how large of an object to expect, and can abort if it's too large. Plus you can read the whole object in one syscall, another performance win
Show this threadThanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.