Logging, interfaces, and allocation
This post is about some new compiler optimizations scheduled for Go 1.9, but I want to start with logging.
A couple of weeks ago, Peter Bourgon started a thread on golang-dev about standardizing logging. Logging is pervasive, so performance came up quickly. The go-kit log package uses structured logging, centered on this interface:
type Logger interface { Log(keyvals ...interface{}) error } Sample call:
logger.Log("transport", "HTTP", "addr", addr, "msg", "listening") Note that everything that goes into a logging call gets converted into an interface. This means that it allocates a lot.
Don't Panic