Speedup the building time by 10x with ccache
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- c, cmake, linux
- Domain
- build-system, ci-cd, documentation
Research direction
Start by reviewing BUILDING.md and the repository's current CI setup to see how CMake and compiler commands are configured. Document ccache usage for GMT developers and evaluate enabling it in CI, with completion shown by clearer build instructions and a measurable rebuild or CI benefit.
Written by the indexing model from the issue text.
Description
Quote from the ccache homepage:
Ccache is a compiler cache. It speeds up recompilation by caching previous compilations and detecting when the same compilation is being done again.
I did some tests on my Linux machine.
Without ccache
$ mkdir build
$ cd build
$ cmake .. -G Ninja # 9.17s user 7.43s system 99% cpu 16.651 total
$ ninja # 360.21s user 16.89s system 2973% cpu 12.683 total
Cmake configuration takes ~16 s and building takes ~12 s (parallel building with many cores using Ninja). For reference, the Linux CI we're using has two cores, and the building step takes about 90 s.
With ccache
After setting up ccache (for instruction about setting up ccache, see below), the building step is accelerated significantly.
$ mkdir build
$ cd build
$ cmake .. -G Ninja # 11.88s user 9.39s system 99% cpu 21.480 total
# first time building after setting up ccache
$ ninja # 383.69s user 25.69s system 3134% cpu 13.059 total
# clean up
$ ninja clean
# 2nd time building after setting up ccache
$ ninja # 1.51s user 1.38s system 245% cpu 1.182 total
As you can see, the 2nd building takes only 1 s. It's 10x faster!
PS: I also tried using make -j2 (make with two cores), the building times are 90 s and 3 s without/with ccache. So it's 30x faster with ccache!
ccache stores compiler cache in the ~/.cache/ccache directory by default, so it still works even if you delete the entire build directory and rebuild everything.
$ cd ..
$ rm -r build
$ mkdir build
$ cd build
$ cmake .. -G Ninja
# 3rd time building after setting up ccache, but it's the first time building in this build directory
$ ninja # 1.52s user 1.41s system 248% cpu 1.181 total
Setting up ccache
Setting up ccache is also very easy. You just need to prefix your compilation command with ccache, i.e., use ccache gcc instead of gcc. This can be done by:
export CC="ccache gcc"
export CXX="ccache g++"
or see https://github.com/ccache/ccache/blob/master/doc/INSTALL.md#installation for other ways.
Actually, you even don't need to setup ccache, because the package manager may already does it for you.
On Fedora, sudo dnf install ccache installs ccache and it also creates some symbol links. After installing ccache, I have
$ which gcc
/usr/lib64/ccache/gcc
$ ll /usr/lib64/ccache/gcc
lrwxrwxrwx. 1 root root 16 Sep 24 15:19 /usr/lib64/ccache/gcc -> ../../bin/ccache
Summary
In summary, ccache is a useful tool for GMT developers who build GMT very often. We should document it in the BUILDING.md and also use it in our CI.
Please let me know what you think and if ccache works for you.
- Dominant language
- C
- Stars
- 997
- Forks
- 420
- Avg merge
- 13h 27m
- Merged PRs (30d)
- 47
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from GenericMappingTools/gmt
-
Add support for SCM 9.0.0 to GMTPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
GenericMappingTools/gmt#9316 · 10 comments · 1 reaction ·
Maintainers usually reply within 1 day
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
GenericMappingTools/gmt#5767 · 15 comments ·
Maintainers usually reply within 1 day
-
discussion
Difficulty 5/5 Over a week Newbie friendliness 35/100
GenericMappingTools/gmt#9343 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 45/100
GenericMappingTools/gmt#9331 · 1 reaction ·
Maintainers usually reply within 1 day
-
histogram: the min/max setting in -T is ignored when -R is setPossibly taken @seisman claimed this 1 day ago. Openbug
Difficulty 3/5 1-2 days Newbie friendliness 55/100
GenericMappingTools/gmt#9330 · 1 reaction ·
Maintainers usually reply within 1 day
All issues in GenericMappingTools/gmt
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
espressif/esp-iot-solution#856 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Broken links in reference manualPossibly taken @farisbasha claimed this 14 days ago. Opencore:meson
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
mpv-player/mpv#18934 · 3 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100