Finding imports that increase memory usage

142 views
Skip to first unread message

Cyrill Troxler

unread,
Aug 23, 2025, 8:09:48 PM (13 days ago) Aug 23
to golang-nuts
I noticed that simply importing certain modules can substantially increase observed RSS even though nothing is visibly being allocated on the heap when looking at pprof. For example, take the following program:

```
package main

import (
"time"
)

func main() {
time.Sleep(time.Hour)
}
```

Running this with go 1.24.6 and running it shows an RSS of 1688 KB (using ps).

```
VSZ       RSS
1225172   1688
```

Now as an example, I just add the following import: `_ "google.golang.org/grpc"`

The RSS of the otherwise same program looks like this:

```
VSZ       RSS
1646164   9896
```

First off, what exactly is causing this rather big increase in RSS here? Is there any way to reduce this and if not, what is the best way to find such heavy dependencies?

I have used https://github.com/Zxilly/go-size-analyzer with some success but this just looks at the binary size and is not very granular, e.g. I have no way of knowing what exactly inside of the grpc module is causing this.

Cyrill

Ian Lance Taylor

unread,
Aug 23, 2025, 8:43:10 PM (13 days ago) Aug 23
to Cyrill Troxler, golang-nuts
I didn't double check, but this could be a version of
https://go.dev/issue/62024.

Ian

Cyrill Troxler

unread,
Aug 24, 2025, 12:10:01 PM (12 days ago) Aug 24
to golang-nuts
Thanks for pointing me in that direction, this definitely contributes. I locally replaced golang.org/x/net with a version that does not use html/template and now the RSS of my program is down to 7588 KB. So there's still quite a bit of delta to what it was before importing grpc. As I can't really see anything with pprof I assume this is mostly down to init()? I just found out about GODEBUG=inittrace=1 so I counted those allocations up and got to ~2625 KB:

$ GODEBUG=inittrace=1 go run . &| awk '{b+=$8} END {print b}'
2625600

Now there's still around 3275 KB unaccounted for.

Cyrill
Reply all
Reply to author
Forward
0 new messages