Skip to content

Commit

Permalink
Avoid clearing Prettier cache when not using prettierrc (#303)
Browse files Browse the repository at this point in the history
At Airbnb we've noticed that the Prettier ESLint rule is extraordinarily
slow. When running ESLint with `TIMING=1`, Prettier is two orders of
magnitude slower than our other slowest rules (which come from
eslint-plugin-import mostly).

I spent some time investigating this today. I ran the Chrome DevTools
profiler while running ESLint on a directory with 480 files in it.
Looking at the flame charts, I noticed that this plugin ended up calling
Prettier's pluginSearchDirs.map.pluginSearchDir for every file that was
being linted, even though it was being memoized. Through some logging, I
determined that the Prettier cache was being cleared between every file,
and narrowed it down to this line, which was added here:

  #55 (comment)

It looks like this cache busting was added to make it so long-running
ESLint processes (e.g. for vscode-eslint) would be able to pick up
changes to prettierrc files without having to reload the process.
Thankfully, we don't use a prettierrc file at Airbnb right now, in favor
of putting our Prettier config inline with our ESLint config. So the
quick performance fix for us is to simply skip the cache busting when
this option is not enabled.

In my profiling, this reduces the time spent in ESLint's verifyAndFix
when running on the same 480 files from 34 seconds to 26 seconds, for a
total savings of 8 seconds.

For folks who are using prettierrc files, this is still pretty crappy,
so it would be great to find a better way to do this. Unfortunately my
knowledge of the inner workings of vscode-eslint and ESLint are not
enough to know if there might be a better way to do this--e.g. maybe
there's some ESLint option that we can respect here?
  • Loading branch information
lencioni authored Jun 14, 2020
1 parent 93f7c8b commit 3c8e2d9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion eslint-plugin-prettier.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@ module.exports = {
const filepath = context.getFilename();
const source = sourceCode.text;

if (prettier && prettier.clearConfigCache) {
// This allows long-running ESLint processes (e.g. vscode-eslint) to
// pick up changes to .prettierrc without restarting the editor. This
// will invalidate the prettier plugin cache on every file as well which
// will make ESLint very slow, so it would probably be a good idea to
// find a better way to do this.
if (usePrettierrc && prettier && prettier.clearConfigCache) {
prettier.clearConfigCache();
}

Expand Down

0 comments on commit 3c8e2d9

Please sign in to comment.