Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: use PCH to reduce compile time #3095

Merged
merged 3 commits into from
Sep 4, 2023
Merged

build: use PCH to reduce compile time #3095

merged 3 commits into from
Sep 4, 2023

Conversation

memchr
Copy link
Contributor

@memchr memchr commented Aug 27, 2023

Using precompiled headers can consistently reduce initial build time by approximately 26%, and incremental build time by 30% to 40% in relative terms. However, this comes at the cost of increased disk usage during compilation.

For example, on a single zen2 core, compilation time, not including the linking process:

PCH initial build incremental build total object files generated
no 238.22s 36.839s 244.8 MiB
yes 186.16s 22.202s 505.6 MiB

During meson setup PCH can be disabled with b_pch=false

meson setup build -Db_pch=false

During cmake setup PCH can be disabled with CMAKE_DISABLE_PRECOMPILE_HEADERS=ON

cmake -S . -B ./build -DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON

Caveats

Using precompiled headers makes compilation of source files in src/ uncacheable by ccache

However, this is unlikely to have a significant impact, as the use of global variables and frequent header changes often invalidate the previous cache, leading to a full rebuild.

@vaxerski vaxerski requested a review from fufexan August 27, 2023 20:44
@memchr memchr changed the title build(meson): use PCH to reduce compile time build: use PCH to reduce compile time Aug 31, 2023
Copy link
Member

@vaxerski vaxerski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok from cmake side

@vaxerski
Copy link
Member

vaxerski commented Sep 1, 2023

fuffie got drafted and he should be back next week I believe

Copy link
Member

@fufexan fufexan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Reduced my build time from 42s to 33s. Considering Nix builds are always "initial", this is a great reduction.

@vaxerski vaxerski merged commit 8e9f010 into hyprwm:main Sep 4, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants