# Fix compilation cache updating bug leading to slow builds · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/e563b166b2b70975899c84beb425c8739d05ed65)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: e563b166b2b70975899c84beb425c8739d05ed65

Requested commit: e563b166b2b70975899c84beb425c8739d05ed65

Commit: e563b166b2b70975899c84beb425c8739d05ed65

Tree: bbf22188ad607631e5e6220e1b4f6a4ef1170521

Author: Stephen Gutekanst

Committer: Andrew Kelley

## Message

```
Fix compilation cache updating bug leading to slow builds

While investigating slow build times with [a large project](https://github.com/hexops/mach/issues/124),
I found that the compiler was reading from disk nearly every C source file in my project
when rebuilding despite no changes having been made. This accounted for several seconds of
time (approx. 20-30% of running `zig build` without any changes to the sources.)

The cause of this was that comparisons of file mtimes would _always_ fail (the mtime of the file on
disk was always newer than that stored in the cache manifest), and so the cache logic would always
fall back to byte-for-byte file content comparisons with what is on disk vs. in the cache-reading every
C source file in my project from disk during each rebuild. Because file contents were the same, a cache
hit occurred, and _despite the mtime being different the cache manifest would not be updated._

One can reproduce this by building a Zig project so the cache is populated, and then changing mtimes
of their C source files to be newer than what is in the cache (without altering file contents.)

The fix is rather simple: we should always write the updated cache manifest regardless of
whether or not a cache hit occurred (a cache hit doesn't indicate if a manifest is dirty) Luckily,
`writeManifest` already contains logic to determine if a manifest is dirty and becomes no-op if no
change to the manifest file is necessary-so we merely need to ensure it is invoked.

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>

```

## Parents

- [5d1aab72d92d0ab512464af0d3ffc036467ac011](https://git.cafe/gitcafe/zig/commit/5d1aab72d92d0ab512464af0d3ffc036467ac011?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/e563b166b2b70975899c84beb425c8739d05ed65?format=markdown)
