Skip to content

ccache: PCH timestamp nondeterminism limits clean-build hit rate to ~18% #14701

Description

@DonLakeFlyer

Summary

On a byte-identical clean rebuild (same build dir path, unchanged sources, deterministic generated headers), ccache only hits 587 / 1606 compile calls (~18%) with direct mode. The _deps (CPM) targets hit; essentially all QGC TUs that consume the CMake precompiled header miss.

Evidence

Measured on macOS (Mac Pro, 24 cores, Debug + testing, Qt 6.11.1, clang) while benchmarking the moccache work:

  • Fresh CCACHE_DIR, clean build A → 1606 misses (expected).
  • Delete build dir, reconfigure to the same path, clean build B with the warmed CCACHE_DIR → only 581–587 direct hits, 0 preprocessed hits, ~1000 misses.
  • moc outputs were verified byte-identical between the two builds (100% moccache hit rate, content-hashed), and the MAVLink dialect headers are deterministic, so generated-source churn is ruled out for those inputs.

Practical impact: a warm ccache gave zero wall-clock improvement on a clean build (548 s vs 549 s baseline) in this test.

Suspected cause

Clang embeds a timestamp in PCH files unless compiled with -Xclang -fno-pch-timestamp. Every clean build regenerates cmake_pch.hxx.pch with different bytes, and since the PCH participates in the hash of every TU that uses it, all PCH-consuming TUs miss. The ccache config (tools/configs/ccache.conf) already sets sloppiness = pch_defines,time_macros,..., but per ccache's PCH documentation clang additionally requires -fno-pch-timestamp for reliable PCH hits.

Ref: https://ccache.dev/manual/latest.html#_precompiled_headers

Suggested fix / investigation

  1. Add -Xclang -fno-pch-timestamp to the PCH-related compile options for clang (macOS + Android/iOS toolchains as applicable).
  2. Re-check whether sloppiness needs include_file_mtime,include_file_ctime interplay with the regenerated PCH file.
  3. Verify on Linux CI (GCC has its own PCH constraints — ccache docs recommend -fpch-preamble alternatives / pch_external_checksum).
  4. Re-measure: expect warm-ccache clean-build hit rate to go from ~18% to near 100%, which would compound with the moc caching work for CI clean builds.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions