yrnkrn / zapcc

zapcc is a caching C++ compiler based on clang, designed to perform faster compilations
Other
1.25k stars 61 forks source link

Not faster than Clang #34

Closed kewp closed 5 years ago

kewp commented 5 years ago

Not sure if I'm doing something wrong. Zapcc doesn't run faster than Clang. Even a bit slower.

I'm using Eigen, as well as a library with a ton of templating (autodiff). Also, I'm using a unity build. Any idea why the speedup isn't there?

Zerophase commented 5 years ago

You could try disabling the unity build. My understanding is with modern multicore cpus unity builds are actually slower; unless, you have a complex build system set up to take advantage of parallelism by unity building subprojects. It's somewhere between 4 and 8 physical / hyperthreaded cores where a unity build might actually be slower.

It could also just be the templates.

Zerophase commented 5 years ago

Actually, it's probably the templates. If I remember correctly, templates require a ton of recompiling bits of code. Which might completely invalidate the cache mechanism used by zapcc to speed up compilation.

How the header files are laid out could have an impact too. Try to write code where you can forward declare all types in headers, and get other headers out of header files that do anything other than forward declare types.

There are a ton of issues that could be causing compilation slowdown.

yrnkrn commented 5 years ago

I have seen good speedup with regular Eigen in the past. Try disabling the unity build.

kewp commented 5 years ago

Ok. I disabled the unity build. Now it is much faster.

I thought something like that wouldn't matter - that every step of the compilation process was cached individually? How does pulling everything into one source file change that?

yrnkrn commented 5 years ago

When you compile everything as one file 1 There is no chance for caching between compilation 2 Any change in the combined file invalidates the whole file

kewp commented 5 years ago

I thought that sub-processes were cached. How is using zapcc different than creating a makefile which only builds when dependent files change?

yrnkrn commented 5 years ago

zapcc tries to cache as much as possible that does not depend upon the non-header files. For instance, for Eigen it wil probably cache Matrix<float, 4, 4> instantiation and generated code but will not cache Matrix<myfloat, 4, 4> where myfloat type is defined at a non-header file.