Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memorize which files were not changed since last styling #320

Closed
lorenzwalthert opened this issue Jan 12, 2018 · 4 comments · Fixed by #538
Closed

Memorize which files were not changed since last styling #320

lorenzwalthert opened this issue Jan 12, 2018 · 4 comments · Fixed by #538

Comments

@lorenzwalthert
Copy link
Collaborator

lorenzwalthert commented Jan 12, 2018

Could significantly speedup style_file() and style_dir() when used often as well as pre-commit hooks. Needs new infrastructure .styler folder in root directory.

@lorenzwalthert
Copy link
Collaborator Author

@krlmlr I think this is worth exploring, it goes into the same direction as parallelization. There are quite a few design questions involved with this, so I'd like to hear your opinion on this. Should we use a .styler file? Or store the hashes of the files in a config.styler file, along with some configs?

@krlmlr
Copy link
Member

krlmlr commented Sep 24, 2018

A directory or a separate file would be better, we don't want to mix config data and hash data.

@lorenzwalthert
Copy link
Collaborator Author

lorenzwalthert commented Apr 13, 2019

Also, let's compare our ideas with other source code formatters: black uses a non-portable file stored in some cache, the path to which is system dependent: psf/black#136.
Storing hashed data in the root may also convolute too many directories. Also, note that depending on how this is implemented, the complexity should not be underestimated. For example, caching is invalidated if the styler version changes or if the (hashed) contents to be styled change (alternatively: last modification time with styler is also last overall modification time).

@lorenzwalthert
Copy link
Collaborator Author

lorenzwalthert commented Aug 13, 2019

We can use the R.cache package to make sure we cache things in the right location OS-independently. Then follow: psf/black#109 (comment). We can store version of styler as well as the hash of the file content (requires reading them, as opposed to use file size and modification time), then.

  • read file and hash contents.
  • check if hash is already in cache (including error handling when cache can't be read properly). Potentially using the R package storr for this.
  • if it is, skip that file.
  • if it is not, style and add the hash to the data base.
  • make sure the cache does not grow infinite.

Benefits of this approach are (credits to psf/black#109 (comment)):

  • Moving a file won't invalidate the cache
  • Switching branches in your VCS won't invalidate the cache (since multiple versions of a single file can be cached trivially)
  • Having the same file in multiple different locations will be picked up as already formatted.
  • It's probably easier. The on-disk format is super easy with constant sized hashes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants