Skip to content

Use precompiled headers for building libHalide#8999

Closed
alexreinking wants to merge 5 commits intomainfrom
alexreinking/build-perf
Closed

Use precompiled headers for building libHalide#8999
alexreinking wants to merge 5 commits intomainfrom
alexreinking/build-perf

Conversation

@alexreinking
Copy link
Copy Markdown
Member

@alexreinking alexreinking commented Mar 10, 2026

This PR introduces PCH support for building libHalide. It divides the sources into LLVM and non-LLVM parts; the former additionally precompiling our LLVM_Headers.h header.

On my MacBook Pro M3 Max, this halves the compilation time from 50s to 25s on 18 threads. I hope this will bring a significant improvement to CI, too.

In terms of total CPU time, I observed 1158s before this PR and 607s after, for a 48% net reduction in compilation time. Using Clang's -ftime-report suggests that header parsing now accounts for only 27% (down from 63!) of the compilation time. Templates take 242s (40%) and the rest of the time is spent in the backend (200s / 33%).

@alexreinking alexreinking requested a review from abadams March 10, 2026 04:35
@alexreinking alexreinking added build Issues related to building Halide and with CI code_cleanup No functional changes. Reformatting, reorganizing, or refactoring existing code. labels Mar 10, 2026
@alexreinking alexreinking force-pushed the alexreinking/build-perf branch from a20cacf to d8c6596 Compare March 10, 2026 06:05
@alexreinking alexreinking marked this pull request as draft March 10, 2026 06:43
@alexreinking
Copy link
Copy Markdown
Member Author

Windows doesn't like the HALIDE_EXPORT declarations in Error.h Meanwhile, there's all kinds of weird ODR issues cropping up elsewhere.

Sigh -- I'll revisit after FetchContent is excised.

@alexreinking alexreinking force-pushed the alexreinking/build-perf branch from d8c6596 to 4aabea5 Compare March 23, 2026 18:52
@alexreinking alexreinking marked this pull request as ready for review March 24, 2026 04:50
@alexreinking
Copy link
Copy Markdown
Member Author

The implementation here is pretty ugly because everything is just dumped into one big folder. If we had another subfolder for the LLVM-privileged sources, it would be easier to isolate the build rules.

@alexreinking alexreinking requested a review from mcourteaux March 24, 2026 17:11
@alexreinking
Copy link
Copy Markdown
Member Author

alexreinking commented Mar 24, 2026

@mcourteaux and @abadams -- could I ask you to build locally with this branch and see if it makes a measurable difference for you versus main?

@alexreinking alexreinking force-pushed the alexreinking/build-perf branch from 7f28f63 to 65617c7 Compare April 6, 2026 18:08
@alexreinking
Copy link
Copy Markdown
Member Author

After meeting with @abadams, it seems that this is a net slowdown on highly multicore systems. Because of the lack of CI improvement, the inconsistency of results, and the implementation complexity, I'm closing this PR.

@alexreinking alexreinking deleted the alexreinking/build-perf branch April 6, 2026 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Issues related to building Halide and with CI code_cleanup No functional changes. Reformatting, reorganizing, or refactoring existing code.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants