Change Request: Cache normalized config globals across files to improve performance
ESLint version
v10.10.0 (also present on main)
What problem do you want to solve?
I've been profiling lint times on a larger internal Vue + TypeScript app (~1,000 files, ~1,270 configured globals), and a surprising amount of each run was going into globals handling rather than into rules. Digging in, configured globals get merged and normalized again for every file, and then no-redeclare walks every one of them again, per file.
In more detail: SourceCode#applyLanguageOptions builds a null-prototype object from the ES, sourceType and configured globals and runs normalizeConfigGlobal on each entry, for every file. addDeclaredGlobals then copies that object and re-filters the enabled names. But files that match the same configs already share one languageOptions object (config-array caches the finalized config per matching set), so the answer is the same every time.
no-redeclare (in eslint:recommended) then runs its iterateDeclarations generator and a rest destructure for every variable in the global scope. That includes every configured global, even though a variable with fewer than two possible declarations can never be reported.
On our app the globals handling alone went from ~1.5s to ~0.5s per lint. To make sure it wasn't just our setup, I reproduced it on ESLint's own lib/ + tests/lib/ (742 files) with @eslint/js recommended plus globals.browser (1,169 globals), 3 runs each:
| main | proposed | |
|---|---|---|
globals handling (applyLanguageOptions + finalize) |
1,108–1,149ms | 203–252ms |
no-redeclare |
161–200ms | 17–24ms |
| total lint | 6.86–6.98s | 5.53–5.96s |
So for a pretty ordinary browser project that's roughly 15-20% of the whole lint. With only the built-in ES globals the saving is small (~0.1s), so it mostly helps anyone spreading globals.browser or similar. Reported problems were identical in every run.
I also found #16302, which looked at the same per-file merge and switched it to Object.assign. That helped, but the work still repeats for every file.
What do you think is the correct solution?
Two small, independent changes:
- In
applyLanguageOptions, cache the merged and normalized globals in aWeakMapkeyed on thelanguageOptionsobject. When a file has no inline/* global */comments,addDeclaredGlobalsreuses a cached list of enabled names instead of copying and filtering again. Files with inline globals keep the existing path, and the cached object is never mutated. - In
no-redeclare, skip variables that can't have two declarations (counting identifiers, inline global comments and, withbuiltinGlobals, the configured-global flag) before starting the generator. The count can only overstate what the generator yields, so it never skips a variable that could report.
I've put both on my fork with tests, one branch each so they can land as separate PRs if that's easier to review:
- Globals cache: https://github.com/eslint/eslint/compare/main...Cherry:eslint:perf/cache-config-globals
no-redeclare: https://github.com/eslint/eslint/compare/main...Cherry:eslint:perf/no-redeclare-skip-single-declarations
Participation
- I am willing to submit a pull request for this change.
AI acknowledgment
- I did not use AI to generate this issue report.
- (If the above is not checked) I have reviewed the AI-generated content before submitting.
Additional comments
For transparency: I used AI tooling to help profile and prototype this, and I've gone through the changes and tests myself.
The tests cover inline globals not leaking into later files that share a config, "off" globals staying excluded, files matching different configs keeping their own globals, and the one no-redeclare case where the new count and the generator differ (a config "off" global re-enabled inline and also declared).
Happy to adjust the approach, or split this into two issues if that's easier to track.
Source: eslint/eslint