skip to content

After a TypeScript repository switched to typescript-eslint's type-checked presets, its ESLint job went from 40 seconds to 6 minutes — why, and how do you find what to fix?

level: seniorimportance: should knowfreq 10%

answer

  1. lint now waits for a project build
  2. typed lint is roughly type-check time
  3. plain tsc run as the baseline
  4. TIMING=1 blames the first typed rule
  5. wide include, default projects, reloads, memory

basics

~20 s

Typed linting makes TypeScript build and analyse the whole project before typed rules can run, so lint time approaches type-check time. Time a plain tsc run as the baseline, profile rules with TIMING=1, then check wide tsconfig includes, default-project files and memory.

solid answer

~50 s

With typed rules, typescript-eslint asks TypeScript to build a program for the project before ESLint can lint, and its docs say typed lint time should be roughly the same as type-check time; most of the slowdown comes from typed rules calling the type checker. So time a plain `tsc` run first. If it also takes minutes, the cost is in the types, and TypeScript's own performance tooling applies. If lint is much slower than `tsc`, profile with `TIMING=1`, remembering that the first typed rule absorbs work the others reuse, so measure rules one at a time. Then check for a tsconfig `include` that is missing or too wide, legacy `project` globs with `**`, many `allowDefaultProject` files, objects with different `extraFileExtensions` forcing project reloads, and out-of-memory crashes. `--cache` is no fix: it ignores cross-file type dependencies.

code

bash · 8 lines
bash
# 1. Baseline: how long does type checking alone take?
time npx tsc --noEmit

# 2. The lint run, with the ten slowest rules printed at the end
TIMING=1 npx eslint .

# 3. Verbose typescript-eslint logs for one file (project loads, reloads)
DEBUG='typescript-eslint:*' npx eslint src/refill/submit.ts

go deeper

for a junior

Know that type-checked presets make lint runs much slower because TypeScript must analyse the whole project first.

for a middle

Explain why typed lint time tracks type-check time, and how to read TIMING=1 output without blaming the first typed rule for everyone's cost.

for a senior

Run the diagnosis in order: tsc baseline, rule timings one at a time, then the lint-side culprits such as wide includes, default-project files, extension reloads and memory. Reject --cache as a fix and say why.

for a principal

Decide which typed rules earn their minutes and where the lint job runs, with numbers: once typed linting is configured, the project build is paid, so the debate is about rule time and coverage, not on or off.

## Where the six minutes go Without types, typescript-eslint parses each file on its own, and a lint run costs roughly the sum of per-file parsing and rule time. **Typed linting** changes the shape of the work: TypeScript has to build a **program** for the project (every file the tsconfig includes, plus the declarations they depend on) before typed rules can ask the checker anything. typescript-eslint's documentation sets the expectation directly: typed lint times should be roughly the same as build times, and most slowdowns come from typed rules calling TypeScript's type-checking APIs. For a small project the extra cost is a few seconds. For a large one it can be minutes, which is what the jump from 40 seconds to 6 minutes is telling you. Editors hide much of it through caching; a command-line run pays all of it at once. ## Step 1: a baseline 1. Time a plain `tsc` run on the same tsconfig. 2. Time the lint run. 3. If both take minutes, the **types** are slow, and typed linting inherits that. TypeScript's own tracing and diagnostics are the tools there. 4. If lint is far slower than `tsc`, the cause is on the **lint side**, and the steps below apply. ## Step 2: find the slow rules - `TIMING=1 npx eslint .` prints the ten longest-running rules with their time and share of total rule time. - Because TypeScript caches internally, **the first typed rule to run almost always looks slowest**: it pays for work later rules reuse. Run suspect rules one at a time and compare those numbers. - For verbose logs, `eslint --debug` or `DEBUG=typescript-eslint:*` shows what typescript-eslint is loading and when it reloads a project. ## Step 3: common lint-side culprits | Symptom | Cause | Fix | |---|---|---| | Build output and test fixtures are parsed | tsconfig `include` is missing (same as the widest glob) or uses `**/*` | Point `include` at the source folders you lint | | Legacy `project: ['./**/tsconfig.json']` | Recursive globs cost heavy disk access | Single `*` per segment, or move to `projectService` | | Many files listed in `allowDefaultProject` | Each default-project file builds its own program | Include them in a tsconfig instead | | Objects set different `extraFileExtensions` | The project service reloads the whole project on each change | Share one `extraFileExtensions` array across objects | | `JavaScript heap out of memory` crash | Large or complex types | Simplify the types; `NODE_OPTIONS=--max-old-space-size=8192` as a last resort | Raising the heap limit lets the run finish; it does not reduce the work. ## Reading the numbers Two runs on the same repository show how the baseline steers the work: | `tsc` alone | Lint run | What it means | |---|---|---| | 5 min 10 s | 6 min | Lint is close to type-check time: the cost is the types, so faster types mean faster lint | | 50 s | 6 min | Lint is far slower than type checking: look for wide includes, default-project files, reloads or a slow rule | In the second case `TIMING=1` and typescript-eslint's debug logs usually point at the culprit within one or two runs. ## Single-run mode typescript-eslint distinguishes a **single run** from a long-lived session such as an editor. When it infers a single run, it builds faster immutable programs instead of watch programs; its docs report up to 10-20% faster linting in CI. The inference fires when the `CI` environment variable is `true`, or when ESLint is launched from the project's own `node_modules` binary, and in both cases only when the command has no `--fix`. `TSESTREE_SINGLE_RUN=true` or `false` overrides the inference, and the `disallowAutomaticSingleRunInference` parser option switches it off; typescript-eslint recommends leaving it off. ## What does not help - **`--cache`.** ESLint's cache is per file and does not track cross-file dependencies, so typed rules can report stale results. typescript-eslint does not recommend it. - **Dropping most typed rules but keeping one.** The project build is paid as soon as typed linting is configured; fewer rules trim rule time, not that build. - **Raising memory alone.** It trades a crash for a long run. The usual outcome is a tighter tsconfig `include`, out-of-project files folded into a tsconfig, and a measured list of the few rules worth their time.

  • Why does TIMING=1 often blame the first typed rule?
    TypeScript caches its work internally. The first typed rule to ask the checker about a file triggers the expensive computation, and later typed rules reuse it, so the first one absorbs cost that belongs to typed linting as a whole. Run suspect rules one at a time and compare those timings separately.
  • Is ESLint's --cache a good answer to slow typed linting?
    No. The cache decides per file whether a result is still valid and does not track dependencies between files, so a change in one module can leave stale typed results in files that import it, in both directions. typescript-eslint does not recommend `--cache`; fix the cost instead.
  • Does typescript-eslint's single-run inference apply to an eslint --fix run?
    No. When `--fix` is on the command line, the inference treats the run as not single-run, so typescript-eslint uses watch programs instead of the faster immutable ones. A `--fix` run on a large typed project therefore misses the single-run speed-up that the same check without `--fix` gets.

  • Keeping just one typed rule removes most of the typed-linting cost.
  • ESLint's --cache keeps typed lint results both fast and accurate.
  • The slowest rule in TIMING=1 output is always the one to remove.
  • A tsconfig with no include array limits the program to the files being linted.
  • Raising Node's heap limit makes typed linting do less work.