The Hidden Costs of Go Interfaces: itabs, Escape Analysis and Heap Allocation

A hexagonal architecture port in Go is an interface, and its runtime cost is not simply the dispatch itself. An interface value is two machine words, an itab pointer and a data pointer, and calls go through an indirect function pointer. The main penalty is that the compiler cannot see through the interface, which blocks inlining and makes escape analysis conservatively send pointer arguments to the heap. Storing non-pointer values in interfaces can also trigger boxing allocations, as with integers above 255. The article notes several of these issues remain open in the Go compiler and suggests measuring the effect yourself with a small benchmark and -gcflags=-m.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.



Discussion (0)
Log in to join the discussion and vote.
Log in