styler icon indicating copy to clipboard operation
styler copied to clipboard

Caching of dirty files?

Open krlmlr opened this issue 4 years ago • 3 comments
trafficstars

If I style the same dirty file over and over again, the cache doesn't seem to have an effect. Can you confirm? How to fix?

krlmlr avatar Mar 08 '21 07:03 krlmlr

Right. This was by design because of the following:

  • in most workflows, it's highly unlikely that you style the same input twice. Because after styling, your output will be compliant to the style. So we cache output, not input.
  • Caching output can be done with a hash. All we need to do is look up if the input hashes to a style-guide compliant output. This means we take 0 size on disk.
  • If you want to cache input, you need to store the input (or hash of it) and the output (in plain text) somewhere on disk, which can make the cache grow big after some time.
  • This logic can be found in other source code formatters too.

What is your workflow? I don't think we should cache input for the above reasons and the complexity involved with adding it. A lot can go wrong with caching and I don't think the benefit of adding input caching outweighs the problems introduced (cache size, complexity, very rare use). Also see https://styler.r-lib.org/dev/articles/caching.html.

lorenzwalthert avatar Mar 08 '21 09:03 lorenzwalthert

Rewriting the history for a repository needs fast styling of repetitive inputs.

I don't mind if this lives in a branch for now. Maybe we can make it opt-in?

krlmlr avatar Mar 08 '21 09:03 krlmlr

I see. Let's leave this in a branch for now until we collected further experience with it. Making it optional increases the complexity for the maintainers and users again so I'd rather prefer not to do that.

lorenzwalthert avatar Mar 08 '21 09:03 lorenzwalthert