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: cache results of exec.LookPath #36768
Comments
go run (timing) It may be of interest to the Golang developers to check the timing of other available downloads. go1.13.6.linux-386.tar.gz
Stripping the files from go1.13.6.linux-386.tar.gz the time is slightly different. GNU 1.7 Plan 9 from User Space |
You didn't fill out the issue template. What is the output of Also, what is the output of |
Ok I've updated my post |
Thanks. Unfortunately I still don't see why it is so slow. What is the output of Since this is Windows, the problem may be due to a virus checker. |
Here's the output:
|
Thanks. I was wondering if it were using external linking, but it's not. I have no explanation other than possibly a virus checker. Sorry. |
The From your update it looks like I installed Golang only once on Windows 10 (64-bit). I downloaded a go1.xx.x.windows-amd64.zip file, extracted it, opened an elevated command prompt and moved it to Next I disabled via the context menu indexing for Does locating |
I moved |
I received a reply to an e-mail I sent to Redmond. Doesn't look like it's specific to AV/Defender. The way you rule out (or in) Defender is to temporarily disable it, do the compile, and then compare on vs off times. Looks like they've done that, though. |
The root of the Go tree cannot be included as a value in the Go path. |
I'm not using Windows, my assumption if did you have made any Windows performance tuning e.g. disable timestamp or etc? |
No. I am able to reproduce this behaviour on another PC that is also windows 10 with i7. |
@Zyxon123 asked me to provide the time measurements on Plan 9 for reference.
|
This is sometimes caused by a broken installation. In this Go1.13 install the first you did on your machine? Or did you update Go from an older version you had? Also, when you write:
do you mean reinstalling over the existing version? If yes, can you instead completely nuke every trace of Go from your machine, and try to follow the installation steps again, from scratch? |
Go 1.13.6 is the first version I did on my machine.
I have just uninstalled Go again by deleting
|
@Zyxon123 thanks for trying. If your installation is not broken and you're absolutely sure your antivirus is not disturbing the compilation process, I don't have any other idea to fix this. These kind of slow-compilation-on-windows issues are most commonly caused by a broken installation or by a nosy antivirus. It's clear that there is something wrong with your machines and/or with the way you're installing Go, since many many people are able to compile a Go hello world in < 1s on Windows; but I don't know what that may be. |
Could someone other than the OP add 9pm's time.exe output go1.10.windows-386.zip
|
@apparluk Windows 10 64-bit time output for reference
|
Mind to share the model and brand of your PC, how much free memory does it has? |
The program in which the command Here's a result from Windows 10 (run in 9term.exe). go1.13.7.windows-amd64.zip
I didn't have the opportunity to obtain the specs on the hardware, There was an earlier ticket regarding CRLF, and IIRC, PowerShell (by default) generates UTF-16 content, when running a go executable to output a string, and that is then redirected to a file. |
Measurement on macOS for reference. go1.13.7.darwin-amd64.tar.gz
|
@Zyxon123, does it still run slowly if you try it several times in a rapid succession? For me (with both workspace and Go installation whitelisted in Defender), it drops from
to
And that's on a M.2 drive with 3Gb/s read speed. |
I'm experiencing slow successive builds too. Tried both 1.14.2 and 1.15rc2. I've made sure my GOCACHE is set and excluded it from Windows Defender, among other directories like the Go installation and project directory. I don't think hardware is an issue because building the project within my WSL distro is quick as expected. Hell - it's quicker iteration for me to cross-compile to Windows from the WSL distro! This gave me the idea to try both binaries from the same environment:
For completeness the file contents are:
Both installations were installed similarly - just unzipping the folder and adding Strangely it's not just
Something is definitely wrong but I can't find what. |
Could the difference in build time be explained by the file system bridge that WSL uses? |
Are you saying that since I'm accessing One interesting thing I've noticed is when building with
I think I've narrowed it down to this code range just by playing around with build flags to cause fatal errors that failed quickly. https://github.com/golang/go/blob/go1.14.2/src/cmd/go/internal/work/exec.go#L98-L190 I've got no clue what any of this code does, but I hope I'll find it within myself to keep going and build Go from source with debug print statements to narrow down the slowness further, but I'm considering just working off the MacBook at this point lol |
That's my suggestion. I don't have a WSL host to verify, sorry. |
I'm using go 1.15.6 and this issue still exists on my computer.
This happened when I updated my go version from 1.15.5 to 1.15.6 the other day. |
Does it still occur? When upgrading Go versions, all the cached compilation artifacts are now unused. As a result, everything must be compiled from scratch, which can be slow. Plus this will (eventually) result in a bunch of cache entries that have to get cleaned up, which is also slow. Both of those should be one time effects, though, and things should return to being fast later. |
Possibly related: #38939 |
@duguanyue can you try disconnecting the machine from the network so that is has no internet access, waiting 30s, and the running your hello world again? Is it still slow? |
Hi, I've spent a little while digging into this on my machine. It's hard to be sure we're having exactly the same problem, but my symptoms are I am not familiar with developing the I ended up tracking down the slowness to Digging into this a little deeper, it appears that on Windows (on my machine), If you look at If you consider the number of external processes that are invoked during the normal operation of Once I identified that (at least one possible cause for) the issue was in You can gain further confidence in this being the issue by setting your PATH variable to be just your Go installation: With my normal path:
With PATH set to only my go installation:
With PATHEXT set to only
Same experiment on WSL: With normal PATH:
With limited PATH:
You can further exacerbate the issue on WSL (or presumably Linux in general) by "hiding" gcc from Go:
Note: you may be tempted to think that installing GCC on Windows might circumvent the issue by having it find GCC. On the contrary, invoking GCC seems to in fact increase the time it takes to execute
|
@omaskery useful diagnosis, thanks! |
I can't tell how directly this is related to the actual compilation process, however, as my attempts to print-debug the speed of the go executable didn't go as far as including invocations from within the go compiler itself. All I can tell is that I did make a bit of effort to try and understand the Go compiler enough to try and debug it, but couldn't fumble my way through it, I'm afraid. I can only hypothesise that there's a similar issue going on inside each Go compiler invocation, something about the way it invokes sub-processes, perhaps, or perhaps something else entirely. |
@omaskery Thanks for doing the work of tracking this down. Based on these numbers, it seems like it would be reasonable to try and cache That said, it seems like
On my machine, an |
Now that is interesting! I'm afraid I have no idea what might be causing The source code, compiler, IDEs, etc. are all on NVMe drives, so I don't think it's some kind of I/O latency. My RAM isn't full, so I don't think it's memory constrained. My CPU isn't maxed out, so I don't think it's CPU constrained. I've tried updating every driver I could get my hands on for my machine, wondering if it was some obscure driver issue for certain I/O operations, but that didn't help at all. I do notice that on Linux the |
@omaskery I wish I knew what might cause this. I don't know enough about Windows internals to know what to look for though. If you're running with NVMe drives, I expect you're running on more modern hardware than I am. I'd expect these microbenchmarks to mostly be bottlenecked on RAM speed, but since there's an order of magnitude difference, I'd be very surprised if it were anything hardware related. So my uninformed guess is that this is something related to antivirus or some other system software that runs code when the file system is accessed. |
@jayconrod good intuition! I consulted a Wizard Friend of mine for help diagnosing what might be intercepting my IO, given I thought I had no antivirus installed (and I had tried disabling Windows Defender). They suggested I use Driver View and sent them the output, and they just validated the kernel drivers with their eyes and pointed me at all the suspect ones. I ended up identifying Trusteer Endpoint Security from IBM as the cause! My benchmark output for now:
My Edit: COMPILING GO (as in github.com/golang/go) NOW TAKES ABOUT A MINUTE! So exciting! :) Is this enough evidence to suggest that these issues are just down to antivirus-like software intercepting IO and generally ruining things? |
@omaskery Awesome! Glad you were able to find the culprit. I think that's pretty strong evidence. For cmd/go, I think the right way to handle this is still to cache results of I'll put this on the Go1.17 milestone. Not 100% sure we'll get to it, but it seems like low-hanging fruit as far as optimizations go. |
Awesome!. I close my antivirus and everything is back to normal. |
Can NOT believe it ! The antivirus software affects Golang When I disable |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Hi @ianlancetaylor, can I work on this issue? |
Thanks for offering. That is a question for @jayconrod. I don't know if there are any plans for this already in progress. |
@ch33hau Sure, you're welcome to take a look. I don't think anyone's actively working on this. The simplest thing is probably to wrap calls to We use |
Hi @ianlancetaylor @jayconrod, thank you for the replies and tips, I am glad to hear this! |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Hi,
I followed the steps here after I installed Go. However, running
go run hello.go
takes around 10 - 20 seconds for it to output “hello, world”. Same thing withgo build
. I’ve also tried reinstalling and excluding my Go folder and Go temp folder from windows defender (the only antivirus I use). I've even disabled real time protection. How do I fix this? Any help is appreciated.Thanks!
What did you expect to see?
I expect a hello world program to be compiled within seconds, other users are able to do so.
What did you see instead?
Takes 10-20 seconds to compile instead.
go run -x output
The text was updated successfully, but these errors were encountered: