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

Implement caching mechanism to speed-up formatting of Elm blocks in markdown files #3

Merged
merged 5 commits into from
May 23, 2018

Conversation

kachkaev
Copy link
Member

@kachkaev kachkaev commented May 23, 2018

Prettier parsers and printers work synchronously until prettier/prettier#4459 is discussed and resolved. This means that formatting a markdown file with a large number of Elm blocks takes a while, because for each block a new elm-format is spawned in a sequence.

This PR introduces a simple LRU caching mechanism that works on top of the filesystem. The cache speeds-up consequent formatting of the same text, even between independent prettier executions. Occasionally, garbage collection is invoked to protect cache directory from growing indefinitely.

Each new version of prettier-plugin-elm will use its own cached results, because the value of the version from package.json is mixed with the text to format when generating cache key.

By default, the cache is stored in $TMPDIR/prettier-plugin-elm, but this location can be changed with the environment variable. In practice, this is only needed during testing, so caching can be considered as zero-config.

Caching can be extracted into a separate NPM module as it's pretty generic and I'm happy to do so if someone is interested in reusing it (just ping me).

@kachkaev kachkaev changed the title Implement caching mechanism to speed-up formatting of Elm blocks *.md Implement caching mechanism to speed-up formatting of Elm blocks in markdown files May 23, 2018
@kachkaev kachkaev merged commit 47f9005 into master May 23, 2018
@kachkaev kachkaev added the enhancement New feature or request label May 23, 2018
@kachkaev kachkaev deleted the caching branch September 16, 2018 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant