Skip to content

Memorize which files were not changed since last styling #320

Closed

Description

@lorenzwalthert

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.

Activity

  1. lorenzwalthert commented on Sep 23, 2018

    @lorenzwalthert
    CollaboratorAuthor

    @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?

  2. krlmlr commented on Sep 24, 2018

    @krlmlr
    Member

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

  3. lorenzwalthert commented on Apr 13, 2019

    @lorenzwalthert
    CollaboratorAuthor

    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).

  4. lorenzwalthert commented on Aug 13, 2019

    @lorenzwalthert
    CollaboratorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions