How can I find out why ESLint performance is slow?

44 Views Asked by At

I'm trying to profile my application's usage of ESLint. The only profiling tool I've been able to find provided by ESLint is the TIMING=1 env variable. I've combined with DEBUG=eslint:cli-engine to see the timing per file, and the results still are completely unclear to me.

This is the full output (linting on a single file). The timing results show the longest result taking 400ms (which it claims is 42% of the overall time), however the command actually took 50s to run

TIMING=1 DEBUG=eslint:cli-engine npx --node-options='--max-old-space-size=16240' eslint --fix --quiet --cache ./src/_test/some-test.int.test.ts
  eslint:cli-engine Lint ./src/_test/some-test.int.test.ts +0ms
  eslint:cli-engine Linting complete in: 50192ms +49s
Rule                                    | Time (ms) | Relative
:---------------------------------------|----------:|--------:
import/named                            |   394.573 |    42.4%
@typescript-eslint/no-misused-promises  |   278.482 |    29.9%
import/order                            |   174.813 |    18.8%
import/extensions                       |    11.753 |     1.3%
react/jsx-no-constructed-context-values |     7.815 |     0.8%
import/no-unresolved                    |     6.491 |     0.7%
@typescript-eslint/naming-convention    |     5.245 |     0.6%
react/no-unstable-nested-components     |     3.266 |     0.4%
import/no-relative-packages             |     2.383 |     0.3%
css-modules/no-unused-class             |     2.338 |     0.3%

Are there any other profiling tools I can use to see where this other 50 seconds are coming from? Any ideas on where the hangup might lie?

1

There are 1 best solutions below

2
Matthieu Riegler On

There is beginning of explanation in this issue comment:

import plugin has to parse every dependency, whereas "normal" ESLint rules only need to inspect a small portion of the current file (that has already been parsed). The import parse time is recorded as part of the rule execution.

You'll also notice poor performances for type aware linting rules because it takes time to build the TS AST. More info here