Taming Go’s memory usage, or how we avoided rewriting our client in Rust
The big wins in this article, in what I believe was the order of impact:<p>* They do raw packet reassembly using gopacket, and gopacket keeps TCP reassembly buffers that can grow without bound when you miss a TCP segment. They capped the buffers, and the huge 5G spikes went away.<p>* They were reading whole buffers into memory before handing them off to YAML and JSON parsers. They passed readers instead.<p>* They were using a protobuf diffing library that used `reflect` under the hood, which allocates. They generated their own explicit object inspection thingies.<p>* They stopped compiling regexps on the fly and moved the regexps to package variables. (I actually don&#x27;t know if this was a significant win; there might just be the three big wins.)<p>This is a great article. But none of these seem Go-specific†, or even GC-specific. They&#x27;re doing something really ambitious (slurping packets up off the wire against busy API servers, reassembling them in userland into streams, and then parsing the contents of the streams). Memory usage was going to be fiddly no matter what they built with. The problems they ran up against seem pretty textbook.<p>Frankly I&#x27;m surprised Go acquitted itself as well as it did here.<p>† <i>Maybe the perils of `reflect` count as a Go thing; it&#x27;s worth noting that there&#x27;s folk wisdom in Go-land to avoid `reflect` when possible.</i>