Go build being at most 37x slow on 1.21.5 vs 1.19.3

go 1.19.3 build times:
real 0m 0.10s
user 0m 0.10s
sys 0m 0.05s
(it seems that new users can only include one image per post)

So, I have a problem where I’m building a go image in our CI and it’s taking way too long.
I tried seeing if there’s a huge difference building a simple binary with only a println function that prints ‘hello world’. At most, compiling on go 1.21.5 is around 37x slower than 1.19.3. The environments are official docker hub images, go-1.19:alpine and go-1.21:alpine respectively.

I’d appreciate it if anyone having the same problem can speak to their experience and I’d be super interested in a workaround instead of just waiting for the next version update. Thanks!

See Go 1.20 Release Notes - The Go Programming Language, go distributions no longer come with pre-compiled package archives for the standard library.
Did it help you?

1 Like

You can check if this is the reason for longer build times.
The additional time should be a relatively fixed amount independent from the overall size of the code base.

You could mitigate the problem by creating a new layer in your docker images, which is Alpine+Go+build cache. By compiling the most used parts of the standard library, you can fill the build cache and could speed up subsequent builds on top of this layer.