styler
styler copied to clipboard
Caching of dirty files?
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?
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.
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?
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.