The function Go runs most inside loops
encoding/json.Unmarshal sits inside a loop at 51% of its 172,212 production calls.
encoding/json.Unmarshal
insights
Every count on this page is derived from the snapshot: 9,220 functions, 28.84M callsites, 47 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
encoding/json.Unmarshal sits inside a loop at 51% of its 172,212 production calls.
87,161 in-loop calls. The function Go runs most inside loops.
The function Go runs most inside loops
encoding/json.Unmarshal sits inside a loop at 51% of its 172,212 production calls.
encoding/json.Unmarshal
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 65 of the 9,220 ranked functions.
The busy function that almost never leaves a loop
Among functions with real volume, time.Sleep runs inside a loop more than any other, 62% of its 7,421 production calls.
time.Sleep
The function with the widest reach across the ecosystem
fmt.Sprintf is called from 1,690 of the 2,029 modules in the corpus, roughly 1 in every 1.2.
fmt.Sprintf
The function one codebase hammers harder than anyone
github.com/Azure/go-autorest/autorest.NewErrorWithError makes 215,125 production calls from just 2 modules, about 107,563 calls per module. High volume, almost no breadth.
github.com/Azure/go-autorest/autorest.NewErrorWithError
True ubiquity is rare
Only 20 functions are called in at least half of the 2,029 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 33 of the 47 projects mapped, the common denominator of Go.
fmt.Errorf
The heaviest caller of them all
Kubernetes makes 515,398 production calls across 39 modules, more than any other project we mapped.
Kubernetes
Kubernetes' signature call
Kubernetes leans on k8s.io/kubernetes/test/e2e/framework.ExpectNoError harder than the field does. That is 10,641 production calls from its own modules.
k8s.io/kubernetes/test/e2e/framework.ExpectNoError
Terraform's signature call
Terraform leans on github.com/aws/aws-sdk-go/aws.String harder than the field does. That is 6,492 production calls from its own modules.
github.com/aws/aws-sdk-go/aws.String
TiDB's signature call
TiDB leans on github.com/juju/errors.Trace harder than the field does. That is 3,722 production calls from its own modules.
github.com/juju/errors.Trace
HashiCorp's signature call
HashiCorp leans on github.com/hashicorp/boundary/internal/errors.New harder than the field does. That is 3,611 production calls from its own modules.
github.com/hashicorp/boundary/internal/errors.New
Go's busiest interface method
io.Closer.Close is dispatched more than any other interface method, 58,482 calls that could land on any implementation.
io.Closer.Close
Interfaces are everywhere, but they carry little traffic
Just 4% of the 13,841,342 calls in the corpus go through an interface. Most Go is concrete.
Everyone writes through the same shape
979 modules call io.Writer.Write, and 99% 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, encoding/json.Unmarshal is the corpus's most expensive hot path, about 36x the per-call cost of fmt.Sprintf, and 51% of its calls run inside a loop.
encoding/json.Unmarshal
The cheapest call we benchmarked
Of the hot-path functions we benchmarked on darwin/arm64 (Apple Silicon), strconv.FormatBool is the cheapest, about 1.9 nanoseconds per call.
strconv.FormatBool
Go programs compile their patterns once, not in the loop
regexp.MustCompile costs about 31x a fmt.Sprintf per call, but only 3% 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
testing.common.Fatalf is called 443,834 times from tests, 98% of all its calls.
testing.common.Fatalf
The third-party helper the test suite can't live without
github.com/stretchr/testify/require.NoError is the most-called third-party function in tests, 292,333 calls, 96% of them in test files.
github.com/stretchr/testify/require.NoError
Even a workhorse leans on code generators
27% of fmt.Errorf's 570,823 calls are emitted by code generators. The rest are hand-written.
fmt.Errorf
How much of Go is written by code generators
8% 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 9,220 ranked functions are called 130 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, 92 of them, account for 53% of every production call. A textbook power law.
Ten functions carry a fifth of everything
Just ten functions account for 21% of all 7,434,386 production calls in the corpus.
The standard library punches far above its weight
The 1,525 standard-library functions are 17% of the catalog but do 45% of all production work.
Most catalogued functions are barely used
0% of the 9,220 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.