Skip to content

GH-51138: [Python] Fix ccache efficiency - #51139

Merged
pitrou merged 2 commits into
apache:mainfrom
pitrou:gh51138-python-ccache
Sep 3, 2026
Merged

GH-51138: [Python] Fix ccache efficiency#51139
pitrou merged 2 commits into
apache:mainfrom
pitrou:gh51138-python-ccache

Conversation

@pitrou

@pitroupitrou commented Sep 2, 2026

Copy link
Copy Markdown
Member

Rationale for this change

Our current ccache support for PyArrow currently has two issues:

  1. The custom configuration is set using environment variables, but those are not passed to the build processes according to the CMake doc (I have verified this by enabling ccache logging to see the configuration values for each build command)
  2. Cython-generated C++ sources are written in the temporary build directory (because of build isolation), and therefore their path changes everytime. Consequently, ccache would fail reusing previous compilation results.

What changes are included in this PR?

  1. Pass custom ccache configuration using command-line arguments, not environment variables.
  2. Set the ccache configuration variable base_dir to the temporary build directory so that ccache strips away the build directory and hits previously cached results obtained from a different build directory.

Are these changes tested?

Yes, locally I confirmed that ccache now efficiently reuses compilation outputs for Cython-generated C++ sources.

Before:

real 0m50,313s
user 4m22,991s
sys 0m24,805s

After:

real 0m18,698s
user 1m14,727s
sys 0m7,518s

Are there any user-facing changes?

No.

@github-actionsgithub-actionsBot added the awaiting review Awaiting review label Sep 2, 2026
@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #51138has been automatically assigned in GitHub to PR creator.

@pitrou

Copy link
Copy Markdown
MemberAuthor

@github-actions crossbow submit -g python

@github-actions

Copy link
Copy Markdown

Revision: a66cc75

Submitted crossbow builds: ursacomputing/crossbow @ actions-290df36268

TaskStatus
example-python-minimal-build-fedora-condaGitHub Actions
example-python-minimal-build-ubuntu-venvGitHub Actions
test-conda-python-3.11GitHub Actions
test-conda-python-3.11-dask-latestGitHub Actions
test-conda-python-3.11-dask-upstream_develGitHub Actions
test-conda-python-3.11-hdfs-2.9.2GitHub Actions
test-conda-python-3.11-hdfs-3.2.1GitHub Actions
test-conda-python-3.11-hypothesisGitHub Actions
test-conda-python-3.11-pandas-2.2.2-numpy-2.0.2GitHub Actions
test-conda-python-3.11-spark-masterGitHub Actions
test-conda-python-3.12GitHub Actions
test-conda-python-3.12-pandas-latest-numpy-latestGitHub Actions
test-conda-python-3.13GitHub Actions
test-conda-python-3.13-pandas-latest-numpy-2.1.3GitHub Actions
test-conda-python-3.13-pandas-latest-numpy-latestGitHub Actions
test-conda-python-3.14GitHub Actions
test-conda-python-3.14-cpython-debugGitHub Actions
test-conda-python-3.14-pandas-nightly-numpy-nightlyGitHub Actions
test-conda-python-3.14-pandas-upstream_devel-numpy-nightlyGitHub Actions
test-conda-python-emscriptenGitHub Actions
test-debian-13-python-3-amd64GitHub Actions
test-debian-13-python-3-i386GitHub Actions
test-fedora-42-python-3GitHub Actions
test-ubuntu-24.04-python-3GitHub Actions

@rok

rok commented Sep 2, 2026

Copy link
Copy Markdown
Member

@github-actions crossbow submit test-ubuntu-22.04-cpp -p image=ubuntu-python

@github-actions

Copy link
Copy Markdown

Revision: a66cc75

Submitted crossbow builds: ursacomputing/crossbow @ actions-ba899c1522

TaskStatus
test-ubuntu-22.04-cppGitHub Actions

@pitrou

Copy link
Copy Markdown
MemberAuthor

@github-actions crossbow submit test-ubuntu-22.04-cpp -p image=ubuntu-python

What's this @rok ?

Comment threadpython/CMakeLists.txt Outdated
# 2. Set ccache base_dir to the build output directory as it is typically
# a temporary directory, and would otherwise fail caching because of
# using different paths everytime.
set(ccache_command ${CCACHE_FOUND} keep_comments_cpp=true base_dir=${CMAKE_BINARY_DIR})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per my 🤖 ccache pre-4.8 does not accept compiler options (keep_comments_cpp=true in this case). And testing on an older ccache I get:

> ccache keep_comments_cpp=true base_dir=/tmp gcc --versionccache: error: Could not find compiler "keep_comments_cpp=true" in PATH

So users with old ccache building pyarrow would have this crash.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, are there any Python builds which use an old ccache?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think no, but users might. I think this is obscure enough to ignore.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there was an easy way to query the ccache version we could work around this to ensure a better UX. But I'm not sure how to do that. @kou ?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(for the record, ccache 4.8 was released in March 2023)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kou How about cmake -E env as suggested by @rok above?

$ cmake -E env CCACHE_BASEDIR=/top -- ccache -p |\grep base_dir(environment) base_dir = /top

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can avoid the error but meaningless ccache command is still used (ccache storage is consumed). If it's acceptable, we can use the cmake -E env approach.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why "meaningless"?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because:

Cython-generated C++ sources are written in the temporary build directory (because of build isolation), and therefore their path changes everytime. Consequently, ccache would fail reusing previous compilation results.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're setting CCACHE_BASEDIR precisely to avoid that.

@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting review Awaiting review labels Sep 2, 2026
@pitrou

Copy link
Copy Markdown
MemberAuthor

@github-actions crossbow submit wheelcp311*

@github-actions

Copy link
Copy Markdown

Revision: a66cc75

Submitted crossbow builds: ursacomputing/crossbow @ actions-131e0bf55a

TaskStatus
wheel-macos-monterey-cp311-cp311-amd64GitHub Actions
wheel-macos-monterey-cp311-cp311-arm64GitHub Actions
wheel-manylinux-2-28-cp311-cp311-amd64GitHub Actions
wheel-manylinux-2-28-cp311-cp311-arm64GitHub Actions
wheel-musllinux-1-2-cp311-cp311-amd64GitHub Actions
wheel-musllinux-1-2-cp311-cp311-arm64GitHub Actions
wheel-windows-cp311-cp311-amd64GitHub Actions

rok
rok approved these changes Sep 2, 2026
@github-actionsgithub-actionsBot added awaiting merge Awaiting merge awaiting changes Awaiting changes and removed awaiting changes Awaiting changes awaiting merge Awaiting merge labels Sep 2, 2026
@koukou added the CI: Extra: CUDA Run extra CUDA CI label Sep 3, 2026
@pitrou
pitrouforce-pushed the gh51138-python-ccache branch from a66cc75 to a1df242CompareSeptember 3, 2026 08:33
@pitrou

Copy link
Copy Markdown
MemberAuthor

@github-actions crossbow submit -g python

@pitrou

Copy link
Copy Markdown
MemberAuthor

@github-actions crossbow submit wheelcp311*

@github-actionsgithub-actionsBot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Sep 3, 2026
@github-actions

Copy link
Copy Markdown

Revision: a1df242

Submitted crossbow builds: ursacomputing/crossbow @ actions-db9b456f6a

TaskStatus
wheel-macos-monterey-cp311-cp311-amd64GitHub Actions
wheel-macos-monterey-cp311-cp311-arm64GitHub Actions
wheel-manylinux-2-28-cp311-cp311-amd64GitHub Actions
wheel-manylinux-2-28-cp311-cp311-arm64GitHub Actions
wheel-musllinux-1-2-cp311-cp311-amd64GitHub Actions
wheel-musllinux-1-2-cp311-cp311-arm64GitHub Actions
wheel-windows-cp311-cp311-amd64GitHub Actions

@github-actions

Copy link
Copy Markdown

Revision: a1df242

Submitted crossbow builds: ursacomputing/crossbow @ actions-695eab7643

TaskStatus
example-python-minimal-build-fedora-condaGitHub Actions
example-python-minimal-build-ubuntu-venvGitHub Actions
test-conda-python-3.11GitHub Actions
test-conda-python-3.11-dask-latestGitHub Actions
test-conda-python-3.11-dask-upstream_develGitHub Actions
test-conda-python-3.11-hdfs-2.9.2GitHub Actions
test-conda-python-3.11-hdfs-3.2.1GitHub Actions
test-conda-python-3.11-hypothesisGitHub Actions
test-conda-python-3.11-pandas-2.2.2-numpy-2.0.2GitHub Actions
test-conda-python-3.11-spark-masterGitHub Actions
test-conda-python-3.12GitHub Actions
test-conda-python-3.12-pandas-latest-numpy-latestGitHub Actions
test-conda-python-3.13GitHub Actions
test-conda-python-3.13-pandas-latest-numpy-2.1.3GitHub Actions
test-conda-python-3.13-pandas-latest-numpy-latestGitHub Actions
test-conda-python-3.14GitHub Actions
test-conda-python-3.14-cpython-debugGitHub Actions
test-conda-python-3.14-pandas-nightly-numpy-nightlyGitHub Actions
test-conda-python-3.14-pandas-upstream_devel-numpy-nightlyGitHub Actions
test-conda-python-emscriptenGitHub Actions
test-debian-13-python-3-amd64GitHub Actions
test-debian-13-python-3-i386GitHub Actions
test-fedora-42-python-3GitHub Actions
test-ubuntu-24.04-python-3GitHub Actions

@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting change review Awaiting change review labels Sep 3, 2026
@pitrou

Copy link
Copy Markdown
MemberAuthor

I'm going to merge as CI failures are unrelated.

@pitrou
pitrou merged commit 503cee9 into apache:mainSep 3, 2026
42 of 44 checks passed
@pitroupitrou removed the awaiting changes Awaiting changes label Sep 3, 2026
@pitrou
pitrou deleted the gh51138-python-ccache branch September 3, 2026 09:16
@pitroupitrou mentioned this pull request Sep 3, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@pitrou@rok@kou