Hi, For the AIO stuff I needed to build postgres for windows. And I was a bit horrified by the long compile times. At first I was ready to blame the MS compiler for being slow, until I noticed that using mingw gcc from linux to cross compile to windows is also a *lot* slower than building for linux.
I found some blog-post-documented-only compiler flags [1], most importantly /d1reportTime. Which shows that the include processing of postgres.h takes 0.6s [2] Basically all the time in a debug windows build is spent parsing windows.h and related headers. Argh. The amount of stuff we include in win32_port.h and declare is pretty absurd imo. There's really no need to expose the whole backend to all of it. Most of it should just be needed in a few port/ files and a few select users. But that's too much work for my taste. As it turns out there's a partial solution to windows.h being just so damn big, the delightfully named WIN32_LEAN_AND_MEAN. This reduces the non-incremental buildtime in my 8 core windows VM from 187s to 140s. Cross compiling from linux it's master: real 0m53.807s user 22m16.930s sys 2m50.264s WIN32_LEAN_AND_MEAN real 0m32.956s user 12m17.773s sys 1m52.313s Still far from !windows compile times, but still not a bad improvement. Most of the compile time after this is still spent doing parsing / preprocessing. I sidetracked myself into looking at precompiled headers, but it's not trivial to do that right unfortunately. I think it'd be good if win32_port.h were slimmed down, and more of its contents were moved into fake "port/win32/$name-of-unix-header" style headers or such. Greetings, Andres Freund [1] https://aras-p.info/blog/2019/01/21/Another-cool-MSVC-flag-d1reportTime/ [2] postgres.c Include Headers: Count: 483 c:\Users\anfreund\src\postgres\src\include\postgres.h: 0.561795s c:\Users\anfreund\src\postgres\src\include\c.h: 0.556991s c:\Users\anfreund\src\postgres\src\include\postgres_ext.h: 0.000488s c:\Users\anfreund\src\postgres\src\include\pg_config_ext.h: 0.000151s c:\Users\anfreund\src\postgres\src\include\pg_config.h: 0.000551s c:\Users\anfreund\src\postgres\src\include\pg_config_manual.h: 0.000286s c:\Users\anfreund\src\postgres\src\include\pg_config_os.h: 0.014283s C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\crtdefs.h: 0.009727s ... c:\Users\anfreund\src\postgres\src\include\port\win32_port.h: 0.487469s C:\Program Files (x86)\Windows Kits\10\include\10.0.20348.0\um\winsock2.h: 0.449373s ... C:\Program Files (x86)\Windows Kits\10\include\10.0.20348.0\um\windows.h: 0.439666s
diff --git i/src/include/port/win32_port.h w/src/include/port/win32_port.h index 05c5a534420..b5a44519d98 100644 --- i/src/include/port/win32_port.h +++ w/src/include/port/win32_port.h @@ -43,6 +43,8 @@ #define _WINSOCKAPI_ #endif +#define WIN32_LEAN_AND_MEAN + #include <winsock2.h> #include <ws2tcpip.h> #include <windows.h>