'go run hello.go' taking ~30 seconds on windows

2,282 views
Skip to first unread message

Declan Finn

unread,
Dec 14, 2022, 12:57:40 PM12/14/22
to golang-nuts
Hi,

Platform: Windows 10
Go Version: 1.19.4

Compile and run of the most basic helloworld program is extremely slow on my windows machine, taking roughly 30 seconds every time.
Whereas the exact same program, using the same go version, compiles and runs in under 1 second on my Ubuntu machine.
Why is it so slow on windows?
I asked a collogue to do the same test on his windows machine and he sees the same slowness.
Any help would be greatly appreciated.


Robert Engels

unread,
Dec 14, 2022, 1:09:42 PM12/14/22
to Declan Finn, golang-nuts
I am guessing it is a dns resolution issue during startup. See the GODEBUG netdns settings. 

On Dec 14, 2022, at 11:57 AM, Declan Finn <fin...@gmail.com> wrote:

Hi,
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/d7957ef7-e3c3-44f7-a6bb-0e870562eb0en%40googlegroups.com.

thepud...@gmail.com

unread,
Dec 14, 2022, 3:03:26 PM12/14/22
to golang-nuts
Hi Declan,

Virus scanners can slow things down significantly on Windows, including virus scanners can go into overdrive if you are touching many files, touching files with atypical extensions, or building and then immediately executing a new binary.

To start, you could try temporarily disabling your virus scanner and see if it helps.

If it does help, you might be able to benefit from finer grain changes. Most virus scanners support exclusion lists if you have sufficient privileges. You could try for example excluding (1) the directories with your Go code, (2) the directory shown in 'go env GOCACHE', (3) possibly the directory shown in 'go env GOMODCACHE', and possibly others.

I would be curious to hear your results.

Even if this is not the particular problem you hit, it is something other gophers hit, and it would be nice to document this somewhere if it isn't already.

Separately, I thought that Rust for example would add some default exclusions for Windows Defender, which could be an option for the Go Windows installer. However, I'm not seeing that just now based on some quick spot checking, so maybe that's something Rust only used to do, or perhaps I am thinking of something else.

Finally, especially if you are in a corporate environment, there can be other security agents, network services, proxies, and other agents that can interfere with development performance beyond virus scanners.

Regards,
thepudds

Marcello H

unread,
Dec 15, 2022, 2:11:48 AM12/15/22
to golang-nuts
It can also be something to exclude the tmp directory in which Go compiles when you do a 'go run'
(I assume you meant that when saying 'build and run')

What happens if you just build?
- Is this slow
what happens if you just execute?
- Is this slow?

What happens if you go install some-tool and run that?
- is that slow?

Op woensdag 14 december 2022 om 21:03:26 UTC+1 schreef thepud...@gmail.com:

Henry

unread,
Dec 15, 2022, 4:52:35 AM12/15/22
to golang-nuts
Assuming that it is a basic Hello World program, I don't have such problems on my Windows 11 laptop and like many Windows machines, it has antivirus, etc. running. I think it could be something specific to your machine or environment.

tokintmash

unread,
Jun 19, 2023, 2:46:32 PM6/19/23
to golang-nuts
Hello,

Was there a solution to this? I am having the same issue. Win 10 machine and compiling and running simple lines of code takes ages.

Wojciech S. Czarnecki

unread,
Jun 22, 2023, 7:52:56 AM6/22/23
to golan...@googlegroups.com
Dnia 2023-06-18, o godz. 22:52:58
tokintmash <tokin...@gmail.com> napisał(a):

> Hello,
>
> Was there a solution to this? I am having the same issue. Win 10 machine
> and compiling and running simple lines of code takes ages.

The answer is always the same: turn off your antivirus software for your development tree.

Such delays are due to "heuristics" usually implemented by uploading your exe to the vendor.
Root cause is that after 12 years AV vendors still can not cope with what they pereceive
a "non standard" linker, ie. a Go's one.

hope this helps,

--
Wojciech S. Czarnecki
<< ^oo^ >> OHIR-RIPE

Jet Li

unread,
Jun 22, 2023, 8:47:59 AM6/22/23
to golang-nuts
Like to note that if you mean Windows Defender, there is no way to disable that after Build 20H2 iirc where I was task to deploy Windows 10 and could not find the option in Windows Group Policy settings after the update, if Go app are affected by Windows Defender. Your only option is to use older Windows build and alternative OS, mileage may vary.

Another option, could be impossible to backup VM image as it's on macOS
https://multipass.run/

Amnon

unread,
Jun 23, 2023, 12:28:13 AM6/23/23
to golang-nuts
Someone should publish a benchmark of compiling Go code on Windows, Linux, osX.
People can take this into account when selecting their development platform.
And if enough people complain about Windows machines being several orders of magnitude slower 
than similar priced competing platforms, then maybe Microsoft will take note and fix their Anti-Virus tools.

Henry

unread,
Jun 23, 2023, 12:34:24 AM6/23/23
to golang-nuts
I am running Windows 11 with Kaspersky. I don't have such problems. When it comes to Windows, it isn't as simple as blaming your AV. Windows is a complex OS and it is doing many different things in the background (e.g. doing maintenance, installing updates, etc.).  You should open your Task Manager and see what is hogging your resources. You also need some decent hardware as Windows is a bit resource hungry. You may also check if there is an error with Windows itself. See  Using System File Checker in Windows - Microsoft Support

jake...@gmail.com

unread,
Jun 23, 2023, 11:55:29 AM6/23/23
to golang-nuts
This may be related. I have always had a significant delay when building Go programs on Windows. It mostly happens the first time I build, if I have not built recently. A normal build of a simple program is about 3 seconds of wall clock time, whereas it can take over 20 seconds when it is being slow. Using the Windows tool Process Monitor, I was able to determine that my problem is that a huge number of go standard library files are being read, in their entirety on every build. I thought there was package caching of some sort to avoid this, but apparently not. So about 2,000 standard library files are being read in to build a tiny program. When it is being 'slow' these take around 10-40 milliseconds each. Once things are warmed up, they typically take 0.01 to 0.03 milliseconds each. That seems to account for much of the initial slow build. I am assuming the difference is whether the files are cached in memory by Windows?

I am currently running go 1.19, but have had the same issue for years. Using Windows 10, with anti-virus shut off for the source and build directories.

By the way, the Process Monitor tool from Microsoft can be useful in situations like these, as it can give a good indication of how long every operation is taking.
On Wednesday, December 14, 2022 at 12:57:40 PM UTC-5 Declan Finn wrote:

Rajesh Pandian

unread,
Jun 23, 2023, 2:00:20 PM6/23/23
to golang-nuts
Hi Declan,

What's the full code? Also have you tried using https://learn.microsoft.com/en-us/sysinternals/downloads/procmon and see what it does? 

Hoo Luu

unread,
Sep 19, 2023, 10:55:11 PM9/19/23
to golang-nuts
Windows defender slows apps first time ran. I had replaced several hard disks(HDDs and SSDs) and reinstalled OS systems(win7,win10,win11), nothing changed. After turning off  windows defender, everything returns to normal.

Marcello H

unread,
Sep 20, 2023, 3:03:51 AM9/20/23
to Hoo Luu, golang-nuts
You could leave it on, but exclude the directories that you use (also the temp one)

Op wo 20 sep 2023 om 04:55 schreef Hoo Luu <qq510...@gmail.com>:
--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/IR8v3B1pPCI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/2dcbf249-88d0-4bbd-a0fd-2d3b11d3ea8bn%40googlegroups.com.

Larry Clapp

unread,
Mar 20, 2024, 3:23:46 PMMar 20
to golang-nuts
I found this webpage from MS which talks about configuring Windows Defender.


I'm running a Windows 10 VM via VirtualBox on a MacBookPro. I have my $HOME (where I have all my source code) imported into the VM as the E: drive in the VM. Reading the above and poking around a bit led me to a) exclude the E: drive "folder", and b) exclude the "go.exe" executable.

"go test" time dropped from > 3m to ~6s.

Hope that helps.

-- Larry

Laurent Caumont

unread,
Jul 6, 2024, 5:01:52 PM (2 days ago) Jul 6
to golang-nuts
go compiler is not signed.
It might be interesting to see if signing the executable has an impact on the antivirus scan.
Reply all
Reply to author
Forward
0 new messages