Optimize memory usage by avoiding intermediate buffer in message serialization (#928)
* Optimize memory usage by avoiding intermediate buffer in message serialization
This commit replaces the use of an intermediate buffer in the message serialization process with a direct write-to-buffer approach. The original implementation used MustMarshalBinary() which involved an extra memory copy to an intermediate buffer before writing to the final writeBuffer, leading to high memory consumption for large messages. The new WriteTo function writes message data directly to the writeBuffer, significantly reducing memory overhead and CPU time spent on garbage collection.
* add benchmark for write
* benchmark for 1M/4M/8M
* Tidy up new benchmarks
* Maintain older payload write implementation
---------
Co-authored-by: luozhengjie.lzj <luozhengjie.lzj@alibaba-inc.com> Co-authored-by: Matt Joiner <anacrolix@gmail.com>