llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.62k stars 11.83k forks source link

Loading precompiled headers file (.pch) causes simple function int main() {} to compile in 90 sec/4.1 GB #61750

Open yurivict opened 1 year ago

yurivict commented 1 year ago

Please see the attached shar with reproducer.

The headers from the mlpack project cause Clang to exhibit the problem.

Please: 1) Install mlpack 2) run the run-make-pch.sh script 3) run the run-consume-pch.sh script

run-consume-pch.sh compiles a simple int main() {} function in 90 sec/4.1 GB because mlpack's pch file is loaded.

The scripts follow how CMake creates pch files. When CMake is used enabling precompiled headers for mlpack.hpp causes all C++ modules to go up in memory/time. This defeats precompiled headers - makes it impossible to use them.

clang-14.0.5 FreeBSD 13.1

pch.shar.txt

yurai007 commented 1 year ago

Just out of curiosity - does building with GCC or older Clang suffers with similar problem?

EugeneZelenko commented 1 year ago

@yurivict: Could you please try 16 or main branch?

yurivict commented 1 year ago

Version 17.0.0 (llvm-devel-17.0.d20230221) has the same problem.

pch is created in 190sec 7.8GB pch is consumed by int main() {} in 90 sec 4.1GB # problem (!!!)

The resulting m.cpp.o is 139MB and has a lot of symbols from the pch file, despite m.cpp only having the 'main' function.

yurivict commented 1 year ago

Adding pch file to the command line should make it available in case when the relevant header is actually included. But when it isn't included - having pch in the command line should make no significant difference.