I recently migrated from a 2019 i9 Macbook Pro to a new M1 Max Macbook Pro (64GB on both machines), and to my surprise, my go build times ended up being the same. I started to do some research, and I've found a curious behavior that I'm hoping someone can shed some light on. This is with go 1.17.2, vendored dependencies, in a large project.
For my test, I'm just changing a fmt.Printf() in one source file, to hopefully avoid any caching.
Here's the strange thing. If I do a 'go build' within ~12 seconds of saving that change, my build time is about 16 seconds. If I save that change and wait at least 13 seconds, my build time drops to about 2 seconds. This is repeatable. I run the binary after each build, and can see the changed printf(), so I know it's being compiled.
I then looked at the output of 'go build -x' in each instance, and there are a couple of differences. In the case where I don't wait after saving, at the start of the build, it creates a _gomod_.go file. And then, it runs a compile, which takes the majority of the 16 seconds. In the case where I wait at least 13 seconds after saving the source file, the build does neither of these steps.
Any thoughts/suggestions would be appreciated.
Mark