The function Go runs most inside loops
errors.New sits inside a loop at 31% of its 5,590 production calls.
errors.New
insights
Every count on this page is derived from the snapshot: 41 functions, 384k callsites, 7 mapped projects. Here is what stands out: the loops Go runs hottest, the functions everyone reaches for, and the long tail of everything else. 27 facts in all.
deal me a curiosity
The function Go runs most inside loops
errors.New sits inside a loop at 31% of its 5,590 production calls.
1,751 in-loop calls. The function Go runs most inside loops.
The function Go runs most inside loops
errors.New sits inside a loop at 31% of its 5,590 production calls.
errors.New
Half of all in-loop work comes from a handful of functions
Half of every production call that runs inside a loop traces back to just 7 of the 41 ranked functions.
The busy function that almost never leaves a loop
Among functions with real volume, errors.New runs inside a loop more than any other, 31% of its 5,590 production calls.
errors.New
The function with the widest reach across the ecosystem
strconv.Itoa is called from 236 of the 42 modules in the corpus, roughly 1 in every 0.2.
strconv.Itoa
True ubiquity is rare
Only 40 functions are called in at least half of the 42 modules in the corpus. Almost everything else is niche.
The function nearly every project reaches for first
fmt.Errorf is the single most-called function in 5 of the 7 projects mapped, the common denominator of Go.
fmt.Errorf
The heaviest caller of them all
Kubernetes makes 15,755 production calls across 24 modules, more than any other project we mapped.
Kubernetes
Go (golang.org/x)'s signature call
Go (golang.org/x) leans on fmt.Errorf harder than the field does. That is 1,680 production calls from its own modules.
fmt.Errorf
Hugo's signature call
Hugo leans on strings.Builder.WriteString harder than the field does. That is 1,116 production calls from its own modules.
strings.Builder.WriteString
Docker's signature call
Docker leans on github.com/sirupsen/logrus.WithField harder than the field does. That is 1,035 production calls from its own modules.
github.com/sirupsen/logrus.WithField
Kubernetes' signature call
Kubernetes leans on k8s.io/apimachinery/pkg/util/sets.New harder than the field does. That is 751 production calls from its own modules.
k8s.io/apimachinery/pkg/util/sets.New
Go's busiest interface method
io.Reader.Read is dispatched more than any other interface method, 1,002 calls that could land on any implementation.
io.Reader.Read
Interfaces are everywhere, but they carry little traffic
Just 5% of the 94,690 calls in the corpus go through an interface. Most Go is concrete.
Everyone writes through the same shape
148 modules call io.Writer.Write, and 71% of those calls are dispatched. The target is a file, a buffer, or a socket, decided at runtime.
io.Writer.Write
The priciest hot path in the corpus
Weighted by how often it runs, regexp.MustCompile is the corpus's most expensive hot path, about 98x the per-call cost of fmt.Sprintf, and 5% of its calls run inside a loop.
regexp.MustCompile
The cheapest call we benchmarked
Of the hot-path functions we benchmarked on darwin/arm64, strings.TrimSpace is the cheapest, about 9.4 nanoseconds per call.
strings.TrimSpace
Go programs compile their patterns once, not in the loop
regexp.MustCompile costs about 98x a fmt.Sprintf per call, but only 5% of its calls sit inside a loop. The expensive part stays out of the hot path.
regexp.MustCompile
The most test-bound function in the corpus
github.com/stretchr/testify/assert.Equal is called 5,140 times from tests, 100% of all its calls.
github.com/stretchr/testify/assert.Equal
The third-party helper the test suite can't live without
github.com/stretchr/testify/assert.Equal is the most-called third-party function in tests, 5,140 calls, 100% of them in test files.
github.com/stretchr/testify/assert.Equal
Some functions never leave the test suite
github.com/stretchr/testify/assert.Equal is called 5,140 times, and every single call is inside a test file.
github.com/stretchr/testify/assert.Equal
Even a workhorse leans on code generators
32% of google.golang.org/protobuf/proto.Marshal's 1,240 calls are emitted by code generators. The rest are hand-written.
google.golang.org/protobuf/proto.Marshal
How much of Go is written by code generators
4% of every call in the corpus lives in generated code, such as protobuf and cloud SDKs.
The median Go function is barely called at all
Half of the 41 ranked functions are called 1,039 times or fewer in production. The famous ones are the exception.
A tiny fraction of functions does most of the work
The busiest 1% of functions, 1 of them, account for 12% of every production call. A textbook power law.
Ten functions carry a fifth of everything
Just ten functions account for 60% of all 68,399 production calls in the corpus.
The standard library punches far above its weight
The 33 standard-library functions are 80% of the catalog but do 94% of all production work.
Most catalogued functions are barely used
7% of the 41 ranked functions are called at most once in production code, catalogued, but rarely reached for.
Showing 27 of 27 facts.
Facts are superlatives over production calls (test and generated code excluded, except where a fact is explicitly about them). Cost figures are a coarse, input-independent benchmark seed, expressed relative to a fmt.Sprintf call. See the methodology.