Skip to content

perf(macos): do not open files that have not changed when using the incremental cache - #1491

Merged
dsherret merged 6 commits into
mainfrom
perf/incremental-file-stats
Nov 30, 2026
Merged

dsherret merged 6 commits into
mainfrom
perf/incremental-file-stats

Conversation

@dsherret

@dsherret dsherret commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

With a warm incremental cache, every file was opened and hashed only to find out that it did not change. Opening a file is slow on macOS (about 8µs, compared to under 1µs for a stat), and only scales to a few threads there.

This stores the stats of files (size, modified time, change time, inode and device) along with the hash of their contents, so a file whose stats are the same does not need to be opened. The stat is done where the file would be read, right before opening it.

When it's trusted

  • The content's hash still needs to be in the incremental file, so anything that invalidates that (ex. a plugin or configuration change) also invalidates this.
  • A file that changed within 2 seconds of the run starting is not trusted or stored, because of how precise the times are. The change time is only provided in seconds.
  • The stats are read before the file is opened. Opening the file first and using the stats of what was opened saves almost nothing, because opening it is the slow part (84ms instead of 41ms for the TypeScript files below, compared to 87ms without stats).
  • Symlinks are never trusted.

Only on macOS

  • On Linux, opening a file is fast enough (about 1µs) that it's not worth it. A warm cache was up to 1ms faster with 5,000 files, and the first run was 2ms slower.
  • On Windows, it would be possible for dprint check to say that a changed file is formatted. A write through a memory mapping does not change any of a file's times, and a directory listing additionally does not have the changes made through another hard link or to a file that's still open.

On macOS, the stats caught every way of changing a file that I tried: setting the modified time back, replacing it with a file that has the same size and time, writing through a hard link, writing through a memory mapping, and while it's still open.

Where it's stored. In the incremental file, which has a -stats suffix and the stats before the hashes when stats are used. Only that one file is read and written. Elsewhere and on the CI, the file's name and format don't change, so its bytes stay the same when nothing changed (ex. for a CI cache).

dprint check on an M2 Pro:

Before After
Warm, 5,000 small files 41.2ms 16.0ms
Warm, 6,804 TypeScript files 94.8ms 42.6ms
Warm, 21,073 files 407.9ms 164.6ms
Nothing cached, 5,000 small files 72.7ms 74.6ms
Nothing cached, 6,804 TypeScript files 297.3ms 295.0ms
Nothing cached, 21,073 files 949.0ms 921.7ms

Not tested: network file systems, which may cache attributes.

@dsherret dsherret changed the title perf(unix): do not open files that have not changed when using the incremental cache perf(macos): do not open files that have not changed when using the incremental cache Nov 30, 2026
@dsherret
dsherret added this pull request to stack #1492 November 30, 2026 16:05
Base automatically changed from perf/large-files-first to main November 30, 2026 16:06
@dsherret
dsherret force-pushed the perf/incremental-file-stats branch from d83dde3 to 0470000 Compare November 30, 2026 16:06
@dsherret
dsherret merged commit 574ccb3 into main Nov 30, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant