# The inlining budget is 80, and one call spends 59

> The compiler prints what every construct costs. A make and a map index cost 2 each; a call costs 59; defer and go are not priced at all — they disqualify.

- Published: 2026-11-15
- Tags: compiler, performance, benchmarking
- Source: https://gopheria.com/blog/the-inlining-budget-counted/
- Language: en-US
- Author: Nolan Keir

---
`make([]int, n)` costs 2 against the compiler's inlining budget. So does a map
index. A single call to a function the compiler cannot see through costs 59, out
of a budget of 80.

The compiler has been printing these numbers all along, and almost nobody reads
them.

## Asking the compiler

All numbers: `go1.27.0 darwin/arm64`, Apple M4 Pro, 12 cores, macOS 26.6.2. The
harness is
[`inlinebudget/`](https://github.com/CognatePress/experiments.gopheria.com/tree/main/inlinebudget).

Two flags, two halves of the answer:

```bash
go build -gcflags=-m ./inlinebudget       | grep 'can inline'
go build -gcflags='-m -m' ./inlinebudget  | grep 'cannot inline'
```

The first prints a cost for everything the compiler accepted. The second says
why it refused the rest:

```text
inlinebudget/cost.go:47:6: can inline WithMake with cost 4
inlinebudget/grow.go:...: cannot inline Grow27: function too complex: cost 83 exceeds budget 80
```

**80** is the budget on this toolchain. It has moved between releases before and
will again, which is why every table below carries the version.

The benchmarks further down each carry a
[control pair](/blog/benchstat-or-it-didnt-happen/) — a second row for a
function measured against itself — because one of the two results is a null and
a null is only worth publishing next to the error bar that produced it.

## The price list

Sixteen functions, each one a baseline body plus exactly one construct, so
subtracting the baseline's cost gives that construct's price with nothing else
in the way:

```text
construct              cost   over baseline
Base (reference)          2              —
n + 1                     4             +2
make([]int, n)            4             +2
m[n]  (map index)         4             +2
append(xs, n)             8             +6
if n > 0 { … }            8             +6
panic("…")                9             +7
for _, x := range xs      11            +9
switch n { … }            12           +10
select { … }              14           +12
switch v := v.(type)      15           +13
for i := 0; i < 4; i++    17           +15
f := func() int { … }     27           +25
opaque(n)  (a call)       61           +59
```

The bottom row is the finding. **A single call to a function the compiler cannot
inline costs 59 of the 80.** One such call and a couple of statements is the
whole budget; two of them cannot fit however small the rest of the function is.
That is the real content of "keep functions small" — not the line count, the
call count.

The top rows are the ones that surprised me. `make` allocates a slice and costs
the same as an addition. A map index costs the same as an addition. Neither
price reflects the work at runtime, because the budget is not about runtime
work — it is about how much the inliner would have to paste into the caller.

A closure at 25 is the priciest thing that is not a call, and a `for` loop at 15
costs nearly twice a `range` at 9, which I would have guessed the other way
round.

## The two that have no price

`defer` and `go` are missing from that table, and their absence is the point:

```text
inlinebudget/cost.go:75:6:  cannot inline WithDefer: unhandled op DEFER
inlinebudget/cost.go:101:6: cannot inline WithGo: unhandled op GO
```

No cost is computed. A function containing either is refused before the
accounting starts, so shrinking it does not help and never will. This is
qualitatively different from being over budget, and the compiler says so in
different words — `unhandled op` against `function too complex`.

If you have ever wondered why a two-line function with a `defer` in it did not
get inlined, that is the whole answer.

## Where the edge is

A ladder of forty functions, each one `n += k` longer than the last, walks the
budget to its edge:

```text
can inline Grow25 with cost 77
can inline Grow26 with cost 80
cannot inline Grow27: function too complex: cost 83 exceeds budget 80
```

Three per statement, exactly, and the boundary is a hard `>`: cost 80 is
accepted, cost 83 is not. There is nothing gradual about it.

## Crossing the edge costs nothing

So what does a program lose when a function tips over? For this ladder, nothing
at all:

```text
$ go test -run=^$ -bench='Warmup|Boundary|Direct' -benchmem -count=10 ./inlinebudget |
    grep -v Warmup | benchstat -col /fn -

            │ grow26-inlined │ grow26-control │ grow27-not-inlined │
Boundary-12      1.774n ± 0%      1.767n ± 0%         1.760n ± 1%
Direct-12        1.671n ± 1%      1.663n ± 0%         1.679n ± 1%
```

`grow26-control` is a second row for the same function, so its true delta is
zero — the [control pair](/blog/benchstat-or-it-didnt-happen/) that decides
whether anything else on this line is a result. It came in 0.39% below its own
twin. `grow27-not-inlined` came in 0.79% below, which is inside that.

The not-inlined function is marginally faster, and both readings are noise.

The two rows are two call shapes. `Boundary` reaches the functions through a
`func(int) int` value, which cannot be inlined whatever the budget says, so it
measures the two bodies with the decision removed. `Direct` calls them by name,
which is where the decision applies. They agree, and that agreement is itself
the result: if inlining were worth something here, only one of the two rows
would have moved.

**This benchmark cannot say anything else, and the reason is my harness.** The
ladder's body is `n += 1; n += 2; …`, which the compiler folds to a single
constant addition. Grow26 and Grow27 are the same two instructions with and
without a call around them, and a perfectly predicted call is close to free on
this machine. The ladder prices the budget correctly and measures speed not at
all.

## Crossing the edge with a constructor

The case where the decision has a consequence needs a callee whose body the
caller needs to see into. Two constructors, identical in what they return:

```text
inlinebudget/cost.go:135:6: can inline makeSmall with cost 5
inlinebudget/cost.go:141:6: cannot inline makeSmallFat: function too complex: cost 172 exceeds budget 80
```

Both are called from a site that reads one field and drops the pointer:

```text
            │ ctor=inlinable │ ctor=inlinable-control │      ctor=over-budget       │
            │     sec/op     │  sec/op    vs base     │  sec/op     vs base         │
Escape-12      1.791n ± 0%    1.789n ± 0%  ~ (p=0.489)  7.823n ± 1%  +336.77% (p=0.000)

            │      B/op      │          B/op          │            B/op             │
Escape-12         0.00 ± 0%      0.00 ± 0%  ~            32.00 ± 0%   ?
```

**337% and one allocation**, from the same call-site shape. Not because the call
is expensive — the ladder just showed a call is nearly free — but because
[a callee the compiler cannot see into gets the conservative escape
verdict](/blog/escape-analysis-is-per-call-site/). `makeSmall` is folded into
its caller, the compiler sees the pointer die, and the value stays in the frame.
`makeSmallFat` is compiled without knowing what any caller does, so the pointer
has to be assumed to escape.

That is what the budget actually buys. Not the call, the analysis.

:::note
`makeSmallFat` costs 172, not 83. It is well over the edge rather than one
statement past it, because a body that resists constant folding needs real
statements. The comparison is inlinable against not, not 80 against 83.
:::

## What to do with the number

The price list is not a tuning guide, and treating it as one produces the
folklore it replaces. Two things it is good for.

**Diagnosing a specific function.** When something you expected to be inlined is
not, `-gcflags='-m -m'` names the reason in one line, and the reason is one of
two kinds: a cost that exceeds 80, which shrinking can fix, or an `unhandled
op`, which shrinking cannot. Knowing which before you refactor is most of the
value here.

**Reading the call count rather than the line count.** A function with fifteen
statements and no calls is comfortably inside the budget. A function with three
statements and two calls the compiler cannot see through is not. "Small" turns
out to be the wrong axis and it is the one everybody repeats.

## What this does not measure

Profile-guided optimisation, which raises the budget for call sites a profile
says are hot. Every number here is from a build with no profile, and PGO would
move the boundary for exactly the functions most likely to matter.

The price list is also one construct at a time in a trivial body. Real functions
interact — a `range` over a map inside an `if` is not 9 + 6 + 2 — and the
compiler's accounting has cases this ladder does not exercise.

And the whole table is a single toolchain. `cost 80` is `go1.27.0`; the budget
was different before and the per-construct prices move with the compiler's
internals. The command is more durable than the numbers, which is why it is at
the top rather than the bottom.
