Speedup the building time by 10x with ccache

Đang mở
#7,838 6 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
c, cmake, linux

Hướng nghiên cứu

Bắt đầu bằng việc xem xét BUILDING.md và thiết lập CI hiện tại của repository để biết CMake và các lệnh biên dịch được cấu hình như thế nào. Ghi lại cách sử dụng ccache cho các nhà phát triển GMT và đánh giá việc bật nó trong CI; việc hoàn thành được thể hiện bằng hướng dẫn build rõ ràng hơn và lợi ích đo được khi build lại hoặc trong CI.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
C
Star
997
Fork
420
Merge trung bình
13 giờ 27 phút
Pull request đã merge (30 ngày)
47

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của GenericMappingTools/gmt

Tất cả issue của GenericMappingTools/gmt

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.