treefmt icon indicating copy to clipboard operation
treefmt copied to clipboard

Hash cache

Open infinisil opened this issue 8 months ago • 2 comments

Is your feature request related to a problem? Please describe.

With frequent Git (or similar) operations, treefmt often needs to reformat all files, even though almost none changed, since the timestamps got updated, therefore invalidating the cache.

Describe the solution you'd like

A cache of hashes that are known to be formatted. So when it would format a file, it first checks if its hash is in the cache. If yes, no action necessary. If no, format it and add the new hash to the cache.

Describe alternatives you've considered

Additional context

infinisil avatar May 02 '25 09:05 infinisil

The reason we didn't go for the hashes is because opening and reading all the files to compute them can make the no-op version pretty slow. But maybe we can combine it and only check the hashes when the timestamps change.

zimbatm avatar May 02 '25 10:05 zimbatm

Yeah, as @zimbatm mentioned, we've been toying with this for a while. We're open to suggestions.

I've played around with probabilistic hashing to try to lighten the overhead, and there have been some experiments that try to lean on Git more to determine what has changed. Nothing has borne fruit as of yet, but I'd like to find some time and have another crack at it.

Nixpkgs is the perfect playground for testing new ideas.

brianmcgee avatar May 02 '25 11:05 brianmcgee