-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/go: spends a long time loading packages #61149
Comments
have you ruled out your antivirus being responsible for the slowness |
This is an interesting hypothesis. I do have a Trendmicro installed, and I am sometimes asked to trust the built executable. But how can I detect that the build slowness is due to the antivirus, especially not in the compilation but in the load module phase? |
it downloads and opens a lot of files, antivirus may want to scan those as untrusted content. |
This is an interesting hypothesis. Alas, I am on a corporate computer, and thus can't do much about the antivirus. I do notice something special in the traces, there are large gaps between the For example, there's a large gap of 6 seconds between:
I wonder what is the cause of these seamingly doing nothing gaps? |
I assume it's still opening a lot of files (which may be checked) in that time, even if it doesn't have to download them from the internet. |
Interestingly, the build is fast when building from the What this means, is that there's nothing wrong with my computer, and that go builds can be fast. Indeed, except recently Go builds have always been fast, and this snappiness regardless of machine, platform or program size, is why I love Go so much for so many years since before Go 1.0. Alas, there's still room for improvement, as can be seen in the trace above, there's a mysterious 6s second gap in the very beginning before P.S. the exact steps for building with the vendor directory is:
|
you can build and run a modified tool chain with more detailed trace spans covering the parts that you think are interesting. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I tried to build a program with the following
go.mod
andgo.sum
.gomod.zip
and did a profiling of the build process with the following command:
and got the following trace:
build_trace.zip
then I visualized the trace in https://ui.perfetto.dev/
P.S.
I have asked on both go-nuts and golangbridge, but it seems that the community does not have an answer either.
https://groups.google.com/g/golang-nuts/c/72OsIXVcmCs
https://forum.golangbridge.org/t/very-slow-build-taking-lots-of-time/32149
What did you expect to see?
I expect to see the build finish in 7 seconds, which is indicated by the section
exec.Builder.Do
in the trace.What did you see instead?
I saw the build taking an entire 40 seconds!
with most the time spent in
load.PackagesAndErrors
.A closer look suggests that the culprit might be in the following functions:
Since I can build my program without internet connection, this rules out network issues.
Why is module loading taking so much time (there're only 122 lines in my go.sum)?
How can we reduce the time spent in module loading, or even better eliminate these loading operations?
For many many many years, the most exciting and unbeatable feature of Go is its consistently fast build times on all my programs.
I am kind of surprised that not only is building with the latest release slow, but most of the time is spent on loading modules, instead of actually compiling.
Update 2023/07/07
As described in this comment, the build can be made fast when building with
go mod vendor
. Under vendor mode, the build takes 10s, which is a 4x improvement over the original 40s.However, there's still a mysterious 6s gap in the very beginning, and eliminating this do nothing gap would make build times drop to 4s, which is a 10x improvement!
However, I don't know what causes this gap neither how to remove it. Is this gap due to some sort of warm up or unnecessary checks during start up?
The text was updated successfully, but these errors were encountered: