If you have ever tried to build LibreOffice code, you know that it can take a lot of time. LibreOffice has ~6 million lines of C++ and some Java code (<280k). But, there are tools that can help you build LibreOffice from source code much faster, if you do it repeatedly! Here I discuss how to use one of these tools: “ccache”.
Even with a fast computer, compiling huge amount of C/C++ code takes a lot of time. Compiling 6 million lines of C/C++ code in LibreOffice will take you several minutes (if not hours) with a decent computer with fast CPU and a lot of RAM.
But, people who work on developing LibreOffice need to build it from the source repeatedly. Because only a fraction of the code changes each time, there is a big chance that one can re-use the compiled objects, and that’s where ccache (and similar tools) come in. It caches the compiled objects, and before trying to re-compile the code, searches inside the cache to see if a previously compiled objects are usable.
The caching mechanism speeds up the process a lot, so that instead of for example 1 hour, you get a full re-build in 5 minutes or so, depending the speed of your machine, if everything is untouched. In case files are changed, you may wait more, but eventually a lot less than the previous build time. Please note that this 5 minutes build is on my machine, so you may have longer (or even shorter time) on your system, depending on the hardware, OS, etc. that you are using.
You have to install ccache binaries on your platform to be able to use it. On Linux, you may install it through the distribution package manager. On macOS and Windows, you have to get the binaries from ccache github release page.
Please note that on Windows, there is also a ccache binary from the Cygwin that is not useful. You have to get the binaries from the Github to get reasonable speedup.
The speed up is not as good compared to Linux, but I could reduce the compilation time from 30 minutes to 18 minutes, which helps considerably when you do LibreOffice development. Some developers have reported that using PCH is faster compared to using ccache on Windows.
There are other tools for speeding up the build beyond ccache. For example, icecream is a distributed alternative for ccache.
Also, pre-compiled headers (PCH) are useful to reduce the build time. Please have in mind that combining PCH and ccache/icecream might not always be possible on each and every platform. PCH usage is described in TDF Wiki article, building LibreOffice on Linux:
autogen.sh enables use of precompiled headers (PCH), which reduce build time at the expense of more disk space and more source files possibly rebuilt when a header changes. The option has several levels (system, base, normal, full), the higher level the higher possible gain but also disk space usage and chance for larger rebuilds on changes.
If you like further optimizing the build time, this LibOCon 2022 presentation by Luboš Luňák can be interesting for you: