When files often get touched during builds, the mtime based validation
leads to different problems in implicit modules builds, even when the
content doesn't actually change:
- Modules only: module invalidation due to out of date files. Usually
causing rebuild traffic.
- Modules + PCH: build failures because clang cannot rebuild a module if
it comes from building a PCH.
- PCH: build failures because clang cannot rebuild a PCH in case one of
the input headers has different mtime.
This patch proposes hashing the content of input files (headers and
module maps), which is performed during serialization time. When looking
at input files for validation, clang only computes the hash in case
there's a mtime mismatch.
I've tested a couple of different hash algorithms availble in LLVM in
face of building modules+pch for #import <Cocoa/Cocoa.h>:
- hash_code: performace diff within the noise, total module cache
increased by 0.07%.
- SHA1: 5% slowdown. Haven't done real size measurements, but it'd be
BLOCK_ID+20 bytes per input file, instead of BLOCK_ID+8 bytes from
- MD5: 3% slowdown. Like above, but BLOCK_ID+16 bytes per input file.
Given the numbers above, the patch uses hash_code. The patch also
improves invalidation error msgs to point out which type of problem the
user is facing: "mtime", "size" or "content".