This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Use ccache by default
Type: resource usage Stage: resolved
Components: Build Versions: Python 3.8
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: christian.heimes, lukasz.langa, matrixise, pitrou, rhettinger, steve.dower
Priority: normal Keywords: patch, patch, patch

Created on 2019-02-06 19:25 by pitrou, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 11773 closed pitrou, 2019-02-06 19:33
PR 11773 closed pitrou, 2019-02-06 19:33
PR 11773 closed pitrou, 2019-02-06 19:33
Messages (11)
msg334973 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2019-02-06 19:25
While compiling CPython isn't very slow, enabling ccache if found would produce faster builds when developing.
msg334974 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2019-02-06 19:29
I've got a proof-of-concept patch, here are the results:

Debug build, uncached

real	0m50,260s
user	1m52,663s
sys	0m11,305s

Debug build, cached

real	0m4,511s
user	0m4,009s
sys	0m1,547s

Non-debug build, uncached

real	1m18,384s
user	3m19,271s
sys	0m12,319s

Non-debug build, cached

real	0m4,047s
user	0m3,467s
sys	0m1,621s

This is on a 16-thread CPU.
msg334975 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2019-02-06 19:35
This is Unix-only, but the same approach may be possible on Windows using clcache (https://github.com/frerich/clcache).
msg334977 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-02-06 20:03
I think the caching that MSVC does naturally handles this well enough - certainly rebuilds normally just build those files that have not changed.

Besides not rebuilding .o[bj] files where the sources have not changed, what else do these tools do?
msg334979 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2019-02-06 20:16
The PR is not required. I have been using ccache for many years with a custom PATH. On Debian, it's recommended to modify PATH manually. On Fedora PATH is automatically modified by the ccache package.

$ echo $PATH
/home/heimes/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin
$ ls -la /usr/lib64/ccache/
total 252
drwxr-xr-x.   2 root root   4096 Dec 21 11:23 .
dr-xr-xr-x. 210 root root 249856 Jan 29 10:28 ..
lrwxrwxrwx.   1 root root     16 Dec 21 11:23 c++ -> ../../bin/ccache
lrwxrwxrwx.   1 root root     16 Dec 21 11:23 cc -> ../../bin/ccache
lrwxrwxrwx.   1 root root     16 Dec 21 11:23 g++ -> ../../bin/ccache
lrwxrwxrwx.   1 root root     16 Dec 21 11:23 gcc -> ../../bin/ccache
lrwxrwxrwx.   1 root root     16 Dec 21 11:23 x86_64-redhat-linux-c++ -> ../../bin/ccache
lrwxrwxrwx.   1 root root     16 Dec 21 11:23 x86_64-redhat-linux-g++ -> ../../bin/ccache
lrwxrwxrwx.   1 root root     16 Dec 21 11:23 x86_64-redhat-linux-gcc -> ../../bin/ccache
msg334983 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2019-02-06 20:50
time -p make CC="/usr/bin/ccache gcc" --jobs 4 --silent > stdout.txt ^ stderr.txt

real 4.36
user 3.69
sys 1.73

on a 4-thread CPU

i7-7560U CPU @ 2.40GHz
msg334987 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2019-02-06 21:40
> Besides not rebuilding .o[bj] files where the sources have not changed, what else do these tools do?

That's a different caching scheme.

MSVC, make, ninja and friend will compare timestamps of the .c and .o files are avoid rebuilding if the .o file is younger.  However, this doesn't work when you switch e.g. git branches or compilation options (e.g. from debug to release and vice-versa).  ccache caches compilation results in its own cache directory and hashes command-line arguments as well as source file contenst.  So it covers more situations.
msg334988 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2019-02-06 21:41
(sorry for the typos; a bit sick today)
msg334993 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2019-02-07 00:43
Antoine, thanks for pointing out that ccache exists.  I got immediate build-time improvements.

For the Mac, I did a "brew install ccache" and prepended "/usr/local/opt/ccache/libexec". No modification of our files was necessary.
msg335065 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2019-02-08 09:30
Hi @Raymond

I use this script since 1 year for the compilation of Python,

https://github.com/python/cpython/pull/11773#issuecomment-461179522

#!/usr/bin/env fish

set number_of_cpu (python3 -c "import os; print(os.sysconf('SC_NPROCESSORS_ONLN'))")

./configure --prefix=$PWD-build --with-pydebug --silent -C > stdout.txt ^ stderr.txt
make CC="/usr/bin/ccache gcc" --jobs $number_of_cpu --silent > stdout.txt ^ stderr.txt


Really useful because I use the cache of configure.ac and ccache for makefile. Now we could use distcc (for a distributed compilation or alternative) but I don't think the result will be really significative.
msg402588 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-09-24 21:15
It seems to me like the consensus is to not alter CPython's build files because ccache is supposed to be used through its `cc`/`gcc` compiler wrappers. Those can be provided to a ./configure run either by modifying PATH to include the directory with the wrappers or by specifying the CC env var directly to point to the ccache wrapper (or "ccache gcc").

Therefore, I'm closing the issue. Antoine, this sat for 2.5 years without activity but if you feel strongly about reintroducing the idea, feel free to reopen.
History
Date User Action Args
2022-04-11 14:59:11adminsetgithub: 80102
2021-09-24 21:15:25lukasz.langasetstatus: open -> closed


keywords: patch, patch, patch
nosy: + lukasz.langa
messages: + msg402588
resolution: rejected
stage: patch review -> resolved
2019-02-08 09:30:50matrixisesetkeywords: patch, patch, patch

messages: + msg335065
2019-02-07 00:43:31rhettingersetkeywords: patch, patch, patch
nosy: + rhettinger
messages: + msg334993

2019-02-06 21:41:05pitrousetkeywords: patch, patch, patch

messages: + msg334988
2019-02-06 21:40:15pitrousetkeywords: patch, patch, patch

messages: + msg334987
2019-02-06 20:50:28matrixisesetkeywords: patch, patch, patch
nosy: + matrixise
messages: + msg334983

2019-02-06 20:16:51christian.heimessetkeywords: patch, patch, patch
nosy: + christian.heimes
messages: + msg334979

2019-02-06 20:03:43steve.dowersetkeywords: patch, patch, patch

messages: + msg334977
2019-02-06 19:35:25pitrousetkeywords: patch, patch, patch
nosy: + steve.dower
messages: + msg334975

2019-02-06 19:33:28pitrousetkeywords: + patch
stage: patch review
pull_requests: + pull_request11745
2019-02-06 19:33:25pitrousetkeywords: + patch
stage: (no value)
pull_requests: + pull_request11744
2019-02-06 19:33:21pitrousetkeywords: + patch
stage: (no value)
pull_requests: + pull_request11743
2019-02-06 19:29:30pitrousetmessages: + msg334974
2019-02-06 19:25:25pitroucreate