How can I speed up MinGW-w64's extremely slow C++ compilation/linking?
Compiling a trivial "Hello World" program:
#include <iostream>
int main()
{
std::cout << "hello world" << std::endl;
}
...takes 3 minutes(!) on this otherwise-unloaded Windows 10 machine (i7-6700, 32GB of RAM, decent SATA SSD):
> ptime.exe g++ main.cpp
ptime 1.0 for Win32, Freeware - http://www.pc-tools.net/
Copyright(C) 2002, Jem Berkes <jberkes@pc-tools.net>
=== g++ main.cpp ===
Execution time: 180.488 s
Process Explorer shows the g++
process tree bottoming out in ld.exe
which doesn't use any appreciable CPU or I/O for the duration.
Running the g++
process tree through API Monitor shows there are three unusually long syscalls in ld.exe
: two NtCreateFile()
s and a NtOpenFile()
, each operating on a.exe
and taking 60 seconds apiece.
The slowness only happens when using the default a.exe
output; g++ -o foo.exe main.cpp
takes 2 seconds, tops.
"Well don't use a.exe
as an output name then!" isn't really a solution since this behavior causes CMake to take ages doing compiler feature detection.
GCC toolchain versions:
>g++ --version
g++ (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
>ld --version
GNU ld (GNU Binutils) 2.30
Given that I couldn't repro the problem in a clean Windows 10 VM and the dependence on the output filename led me down the path of anti-virus/anti-malware interference.
fltmc instances
listed several possible filesystem filter drivers; guess-n-check narrowed it down to two of Carbon Black's: carbonblackk
& ParityDriver
.
Using Regedit to disable them via setting Start
to 0x4
("Disabled", 0x2
== Automatic, 0x3
== Manual) in these two registry keys followed by a reboot fixed the slowness: