Skip to content

Commit 3c8e2d9

Browse files
authored
Avoid clearing Prettier cache when not using prettierrc (#303)
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?
1 parent 93f7c8b commit 3c8e2d9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

eslint-plugin-prettier.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,12 @@ module.exports = {
152152
const filepath = context.getFilename();
153153
const source = sourceCode.text;
154154

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

0 commit comments

Comments
 (0)