# One constructor, five call sites, two verdicts

> `-gcflags=-m` printed "escapes to heap" for the constructor and "does not escape" for half the places that call it. The package boundary had nothing to do with it.

- Published: 2026-11-08
- Tags: escape-analysis, compiler, allocation, benchmarking
- Source: https://gopheria.com/blog/escape-analysis-is-per-call-site/
- Language: en-US
- Author: Nolan Keir

---
`go build -gcflags=-m` printed `&T{...} escapes to heap` for a constructor, and
`&T{...} does not escape` for two of the four places that call it.

Same constructor. Same build. The two lines are two apart in the same output,
and the one people quote is the first.

## What is being measured

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

One constructor, small enough that the compiler will consider keeping its result
in a frame:

```go
type T struct {
	V   int
	buf [3]int
}

func New(v int) *T { return &T{V: v} }
```

Five call sites. Three in the same package — one that drops the value, one that
stores it in a package variable, and one that calls a `//go:noinline` copy of
the same constructor. Two more in another package, repeating the first two
verbatim.

The two `drop` sites are the same source compiled into two packages, which makes
them a [control pair](/blog/benchstat-or-it-didnt-happen/) as well as a result:
their true difference is zero, so whatever separates them is the error bar for
everything else in the table.

[Escape analysis is not a rule of thumb](/blog/escape-analysis-is-not-a-rule-of-thumb/)
established that `-m` reports escape analysis rather than allocation, and left a
claim standing in its FAQ: `-m` is per-function, allocation is per-call-site.
This is that claim measured.

## What the compiler prints

```text
$ go build -gcflags=-m ./callsite ./callsite/remote
# gopheria.lab/callsite
callsite/ctor.go:19:6: can inline New
callsite/ctor.go:32:6: can inline Drop
callsite/ctor.go:38:6: can inline Keep
callsite/ctor.go:46:6: can inline Sealed
callsite/ctor.go:33:10: inlining call to New
callsite/ctor.go:39:10: inlining call to New
callsite/ctor.go:19:29: &T{...} escapes to heap
callsite/ctor.go:26:35: &T{...} escapes to heap
callsite/ctor.go:33:10: &T{...} does not escape
callsite/ctor.go:39:10: &T{...} escapes to heap
# gopheria.lab/callsite/remote
callsite/remote/remote.go:11:6: can inline Drop
callsite/remote/remote.go:17:6: can inline Keep
callsite/remote/remote.go:12:19: inlining call to callsite.New
callsite/remote/remote.go:18:19: inlining call to callsite.New
callsite/remote/remote.go:12:19: &callsite.T{...} does not escape
callsite/remote/remote.go:18:19: &callsite.T{...} escapes to heap
```

Line 19 is `New` itself: **escapes to heap**. Line 33 is `New` inlined into a
caller that reads one field and drops the pointer: **does not escape**. Line 39
is `New` inlined into a caller that stores the pointer in a package variable:
escapes, correctly.

The `can inline` and `inlining call to` lines are the decision being made, and
they are why the verdicts multiply: each `inlining call to New` produces a fresh
copy of the constructor's body inside a caller, and each copy gets analysed in
that caller's context. Five lines of escape verdict for one composite literal,
because the compiler analysed it five times.

Four verdicts about one constructor, and they are not the same verdict. The
column numbers are the tell — `19:29` is the composite literal inside `New`,
`33:10` and `39:10` are that same literal after it was folded into two different
callers.

Now the same build with inlining off:

```text
$ go build -gcflags='-m -l' ./callsite ./callsite/remote
callsite/ctor.go:19:29: &T{...} escapes to heap
callsite/ctor.go:26:35: &T{...} escapes to heap
```

Two lines. Every call-site verdict is gone, because nothing was inlined into
anything and the compiler had only the per-function question to answer. **This
is the output that matches the mental model most people have**, and it describes
a program nobody ships.

## What it costs

```text
$ go test -run=^$ -bench='Warmup|CallSite' -benchmem -count=10 ./callsite |
    grep -v Warmup | benchstat -col /site -
```

```text
            │ same-package-drop │ same-package-keep │ same-package-sealed │ cross-package-drop │ cross-package-keep │
            │      sec/op       │      sec/op       │       sec/op        │      sec/op        │      sec/op        │
CallSite-12        1.841n ± 2%         6.746n ± 1%           6.877n ± 1%          1.880n ± 1%          6.636n ± 1%
                                    +266.50%              +273.62%          ~ (p=0.060)           +260.55%

            │       B/op        │       B/op        │        B/op         │       B/op         │       B/op         │
CallSite-12          0.00 ± 0%         32.00 ± 0%           32.00 ± 0%           0.00 ± 0%           32.00 ± 0%
```

**3.7 times and one allocation**, between two call sites of the same constructor
in the same file. The 32 bytes are what `T` costs on the heap; at that size the
allocation itself is
[one of the cheap ones](/blog/the-thirty-percent-smaller-allocation/), and it is
still most of the 6.7 ns.

## The boundary that is not a boundary

The two `drop` rows are the same code in two packages. Their delta is `~` at
p=0.060 — 1.841 ns against 1.880 ns, zero allocations either way.

That is the result I expected least. A package boundary feels like it should be
an analysis boundary: the compiler is compiling `remote` without `callsite`'s
source in front of it. But export data carries inlinable function bodies across,
so `callsite.New` is available to be folded into `remote.Drop` exactly as it is
into `callsite.Drop`, and the verdict follows the body rather than the file.

The `keep` rows say the same thing from the other side. `same-package-keep` and
`cross-package-keep` both store the pointer in a package variable, both allocate
32 bytes, and they land at 6.746 ns and 6.636 ns — the cross-package one
marginally *faster*, which is noise rather than a finding. When the value
genuinely escapes, the boundary does not make it escape harder.

Read the four rows together and the package column is empty. Two shapes of call
site, each measured twice on either side of a boundary, and the boundary
explains none of the variation.

The two `drop` rows also serve as this table's control. They are the same source
compiled into two places, so their true difference is zero, and the 2% between
them is the error bar every other column has to clear. All three `keep`-shaped
columns clear it by a factor of a hundred.

## What actually decides it

`same-package-sealed` is the row that names the mechanism. It calls a copy of
the constructor marked `//go:noinline`, from a call site that drops the value
immediately — the same shape as `same-package-drop`, which allocates nothing.

It allocates 32 bytes.

```go
//go:noinline
func NewSealed(v int) *T { return &T{V: v} }

func Sealed(v int) int {
	t := NewSealed(v)
	return t.V   // dies here, and allocates anyway
}
```

The compiler compiled `NewSealed` without knowing what any caller would do with
the result, so it had to assume the pointer outlives the frame. The caller, in
turn, could not see inside it. Neither half of the program had the information,
and the conservative answer is the only one available.

So the axis is not *where* the constructor lives. It is whether the caller could
see into it — which makes the escape verdict downstream of the inlining
decision, and the inlining decision is a budget the compiler keeps.

:::note
`//go:noinline` is used here as an instrument, not as advice. It is how you hold
inlinability fixed while changing nothing else; reaching for it in real code
usually means you are working around a measurement you have not taken.
:::

## Reading both flags

The practical shape of this:

**`-m` is what your program does.** Every `inlining call to` line is followed by
a verdict about the inlined copy, and those verdicts are per call site. This is
the output to read when you want to know whether a particular caller allocates.

**`-m -l` is what the function is.** One verdict per function, no call sites,
and it is the conservative one — because with inlining off, every function has
to be compiled as if any caller might keep anything it returns.

Quoting the second while believing you have measured the first is how a
constructor acquires a reputation. The line that reads `escapes to heap` next to
a definition is true and says nothing about the four places that call it.

## What this does not measure

Whether any of this matters in a real program. One allocation of 32 bytes is
5 ns; a handler doing it once per request will never notice, and one doing it a
million times in a loop will. The profile that tells you which you have is
[a different tool](/blog/pprof-alloc-space-versus-inuse-space/) and it comes
first.

The constructor here is also the easiest possible case: a small struct, no
interfaces, no closures, no slices growing out of it. The verdicts get harder to
predict as soon as a value crosses an interface, and `-m` gets correspondingly
more useful and more confusing at the same time.

And this measures one Go version. Inlining budgets have moved between releases
before, and a constructor that is inlinable today is one refactor — or one
compiler change — away from being the sealed row instead.
