meson: Add support for building with precompiled headers

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-hackers(at)postgresql(dot)org, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, Justin Pryzby <pryzby(at)telsasoft(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>
Subject: meson: Add support for building with precompiled headers
Date: 2022-10-05 19:08:29
Message-ID: 20221005190829.lda7ttalh4mzrvf4@awork3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

This is a patch split off from the initial meson thread [1] as it's
functionally largely independent (as suggested in [2]).

Using precompiled headers substantially speeds up building for windows, due to
the vast amount of headers included via windows.h. A cross build from
linux targetting mingw goes from

994.11user 136.43system 0:31.58elapsed 3579%CPU
to
422.41user 89.05system 0:14.35elapsed 3562%CPU

The wins on windows are similar-ish (but I don't have a system at hand just
now for actual numbers). Targetting other operating systems the wins are far
smaller (tested linux, macOS, FreeBSD).

This is particularly interesting for cfbot, which spends a lot of time
building on windows. It also makes developing on windows less painful as the
gains are bigger when compiling incrementally, because the precompiled headers
don't typically have to be rebuilt.

As a prerequisite this requires changing the way FD_SETSIZE is defined when
targetting windows.

When using precompiled headers we cannot override macros in system headers
from within .c files, as headers are already processed before the #define in
the C file is reached.

A few files #define FD_SETSIZE 1024 on windows, as the default is only 64. I
am hesitant to change FD_SETSIZE globally on windows, due to
src/backend/port/win32/socket.c using it to size on-stack arrays. Instead add
-DFD_SETSIZE=1024 when building the specific targets needing it.

We likely should move away from using select() in those places, but that's a
larger change.

Michael, CCing you wrt the second patch, as Thomas noticed [3] that you were
looking at where to define FD_SETSIZE.

Greetings,

Andres Freund

[1] https://www.postgresql.org/message-id/20211012083721.hvixq4pnh2pixr3j%40alap3.anarazel.de
[2] https://www.postgresql.org/message-id/e0c44fb2-8b66-a4b9-b274-7ed3a1a0ab74%40enterprisedb.com
[3] https://www.postgresql.org/message-id/CA+hUKG+50eOUbN++ocDc0Qnp9Pvmou23DSXu=ZA6fepOcftKqA@mail.gmail.com
[4] https://www.postgresql.org/message-id/20190826054000.GE7005%40paquier.xyz

Attachment Content-Type Size
v2-0001-windows-adjust-FD_SETSIZE-via-commandline-define.patch text/x-diff 6.4 KB
v2-0002-meson-Add-support-for-building-with-precompiled-h.patch text/x-diff 18.6 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Garen Torikian 2022-10-05 19:34:49 Re: [PATCH] Expand character set for ltree labels
Previous Message Nathan Bossart 2022-10-05 19:00:55 Re: Startup process on a hot standby crashes with an error "invalid memory alloc request size 1073741824" while replaying "Standby/LOCK" records