Very slow build taking lots of time

Recently, my go build has been very slow.
The trace below suggests that while compilation itself (exec.Builder.Do) is pretty fast taking 7s,
loading modules (load.PackagesAndErrors) is excruciating slow, taking 31s!

build.trace (2 MB) - Perfetto UI

Most of the time is spent on

  • modload.loadImport

What are these functions doing? How can we eliminate them or speed them up?

Hi @fumin, the trace link does not seem to open for me. I get an error saying the trace cannot be found.

Without a closer look, it could be that your build downloads a lot of modules, or large modules, possibly over a slow connection. Did you trace network activity during the build?

Hi Christoph

Sorry, it seems that the link is local only.
I have uploaded the trace file to:

You can open it on

Without a closer look, it could be that your build downloads a lot of modules, or large modules, possibly over a slow connection

I can build my program without network, so connection issues are ruled out.
I am aware that the disk on my laptop is pretty slow, so this might be an issue.
However, I wonder how can I prove this? I presume loading modules does require a lot disk lookup operations?

What version are you on? I noticed with my current version builds are noticeably slower than on 1.19. Here’s my version:

go version go1.20.4 windows/amd64

If you’re on 1.20, you could try downgrading to 1.19. I assumed it was something messed up with my local install, but if you are experiencing the same thing there might be a chance it’s related to 1.20? Not sure.

That’s an interesting find! How big is the difference, @Dean_Davidson?

@fumin I would also try another machine, if possible, to rule out machine-specific problems.

It’s hard to say because I didn’t do any benchmarks previously but it certainly feels quite a bit slower. I have a pretty fast development machine and on some of my projects I cortesi/modd to watch and continuously build my API (similar to using something like preact watch but for my back-end) so I am especially sensitive to slowdowns in build time. It’d be interesting to see if vendoring my dependencies fixed the problem (since @fumin noted that most of the time is spent on

For me, it’s a minor annoyance and as I mentioned I just assumed it was something in my environment so I didn’t spend too much time troubleshooting it. And if it’s a regression in version 1.20 it will almost certainly be found and fixed at some point.

1 Like

I am running go version

go version go1.20.4 windows/amd64

The speed is pretty much the same on my other laptop, which is running 1.19.

This update comes late, maybe too late, but I want to share this article about Go build times that can help shed some light on slow build times:

Analyzing Go Build Times | howardjohn’s blog

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.