Why go build/test is so slow on Windows

Why go build or go test is so slow on Windows

Problem

When you run go build or go test on Windows, it is very slow.

If go build costs 10s on Linux, it may cost 70s or more on Windows, which is so annoying.

Reason

The reason is that Windows Defender scans the files generated by go build or go test in real time, which causes the slow.

Solution

Exclude the files used by go:

  • %userprofile%\go\
  • %localappdata%\go-build\
  • <YOUR GO CODE DIR>, e.g. %userprofile%\JetBrains\
  1. Open Windows Defender Security Center
  2. Click "Virus & threat protection"
  3. Click "Virus & threat protection settings"
  4. Click "Add or remove exclusions"
  5. Click "Add an exclusion"
  6. Click "Folder"
  7. Select the above folders one by one

BTW

Maybe you can also exclude the process go.exe in "Exclusions" page, but I haven't tried it.