Making a Go Log Viewer 12x Faster (and the Benchmark Bug That Fooled Me) (opens in new tab)
I built Peacock, a terminal JSON log viewer in Go, and it could not keep up with a busy log stream. So I profiled it with go tool pprof: read the profile, fix the hottest line, re-profile, repeat. On a real 70x240 terminal, throughput went from 52 lines/sec to 651 lines/sec, about 12x. The most useful lesson, though, came from an evening I lost to a bug in my own benchmark. Cleanup: a pointless join/split The base profile flagged a viewport setter eating 8% of CPU. SetContent takes a string a...
Read the original article