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

Speed up eslint with --cache #16267

Merged
merged 1 commit into from
Oct 24, 2024
Merged

Speed up eslint with --cache #16267

merged 1 commit into from
Oct 24, 2024

Conversation

isaacl
Copy link
Member

@isaacl isaacl commented Oct 24, 2024

And also align eslint ignored files with how eslint is automatically run.

This ensures that all contributors run lint on the same set of files. Prior to this change, eslint covers ts files outside ui with its default rules, meaning contributors might commit code with fresh eslint errors that only show up when eslint is run bare, or if an eslint extension is installed in a code editor.

Because this commit adds a global ignore pattern on all folders by default, the bare eslint command run no longer takes additional time over eslint ui. And the --cache flag means lint will usually be dramatically faster than before.

One-off eslint checks on files in ignored directories can still be performed with: eslint <path to file>

Pre-commit run of eslint

$ hyperfine -w 3 -N  'node_modules/.bin/eslint ui'
  Time (mean ± σ):      2.405 s ±  0.018 s    [User: 4.728 s, System: 0.316 s]
  Range (min … max):    2.374 s …  2.444 s    10 runs

Post-commit run of eslint, without the ui argument. (faster because of the more efficient global ignore patterns)

$ hyperfine -w 3 -N  'node_modules/.bin/eslint'
  Time (mean ± σ):      2.203 s ±  0.011 s    [User: 4.338 s, System: 0.296 s]
  Range (min … max):    2.188 s …  2.225 s    10 runs

Post-commit example of lint script if repeatedly run. This is much faster, thanks to --cache.

$ hyperfine -w 3 -N  'node --run lint'
Benchmark 1: node --run lint
  Time (mean ± σ):     487.3 ms ±   2.4 ms    [User: 606.9 ms, System: 85.5 ms]
  Range (min … max):   483.7 ms … 491.0 ms    10 runs

I've also added --cache to prettier format scripts. Note that while prettier automatically manages the cache for most tooling updates, it does not clear cache on prettier plugin updates (which we aren't currently using). Nonetheless, to future proof our prettier cache, I'm purposely leaving --cache off the pre-commit hook, which ensures the prettier cache will be often cleared. The cache is still useful when repeatedly running format or when using watch-format.

$ hyperfine -w 3 -N  'node --run format'
  Time (mean ± σ):      4.656 s ±  0.066 s    [User: 7.785 s, System: 0.896 s]
  Range (min … max):    4.594 s …  4.808 s    10 runs

Post-commit example of prettier under repeated use, now much faster thanks to --cache

$ hyperfine -w 3 -N  'node --run format'
  Time (mean ± σ):      1.777 s ±  0.022 s    [User: 1.879 s, System: 0.646 s]
  Range (min … max):    1.751 s …  1.814 s    10 runs

And also align eslint ignored files with how eslint is
automatically run.

This ensures that all contributors run lint on the same
set of files. Prior to this change, eslint covers ts files
outside ui with its default rules, meaning contributors might
commit code with fresh eslint errors that only show up when
eslint is run bare, or if an eslint extension is installed in
a code editor.

Because this commit adds a global ignore pattern on all folders
by default, the bare `eslint` command run no longer takes
additional time over `eslint ui`. And the --cache flag means
lint will usually be dramatically faster than before.

One-off eslint checks on files in ignored directories can still be
performed with: `eslint <path to file>`

Pre-commit run of eslint
```
$ hyperfine -w 3 -N  'node_modules/.bin/eslint ui'
  Time (mean ± σ):      2.405 s ±  0.018 s    [User: 4.728 s, System: 0.316 s]
  Range (min … max):    2.374 s …  2.444 s    10 runs
```

Post-commit run of eslint, without the ui argument.
(faster because of the more efficient global ignore patterns)

```
$ hyperfine -w 3 -N  'node_modules/.bin/eslint'
  Time (mean ± σ):      2.203 s ±  0.011 s    [User: 4.338 s, System: 0.296 s]
  Range (min … max):    2.188 s …  2.225 s    10 runs
```

Post-commit example of lint script if repeatedly run.
This is much faster, thanks to --cache.

```
$ hyperfine -w 3 -N  'node --run lint'
Benchmark 1: node --run lint
  Time (mean ± σ):     487.3 ms ±   2.4 ms    [User: 606.9 ms, System: 85.5 ms]
  Range (min … max):   483.7 ms … 491.0 ms    10 runs
```

----

I've also added --cache to prettier format scripts.
Note that while prettier automatically manages the cache for most
tooling updates, it does not clear cache on prettier plugin updates
(which we aren't currently using). Nonetheless, to future proof our
prettier cache, I'm purposely leaving --cache off the pre-commit hook,
which ensures the prettier cache will be often cleared. The cache is
still useful when repeatedly running format or when using watch-format.

```
$ hyperfine -w 3 -N  'node --run format'
  Time (mean ± σ):      4.656 s ±  0.066 s    [User: 7.785 s, System: 0.896 s]
  Range (min … max):    4.594 s …  4.808 s    10 runs
```

Post-commit example of prettier under repeated use, now much faster
thanks to --cache
```
$ hyperfine -w 3 -N  'node --run format'
  Time (mean ± σ):      1.777 s ±  0.022 s    [User: 1.879 s, System: 0.646 s]
  Range (min … max):    1.751 s …  1.814 s    10 runs
```
@isaacl isaacl requested a review from schlawg October 24, 2024 23:29
@schlawg schlawg merged commit 116f9a0 into lichess-org:master Oct 24, 2024
3 checks passed
@isaacl isaacl deleted the eslintCache branch October 24, 2024 23:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants