eslint-plugin-panda
eslint-plugin-panda copied to clipboard
perf(worker): avoid accessing panda context to scan all files
What kind of change does this PR introduce?
Fixes https://github.com/chakra-ui/eslint-plugin-panda/issues/160
The getFiles() method is part of PandaContext It scans the entire project and returns all files matching the Panda CSS include/exclude patterns. This is slow on large projects (Complexity O(N)).
Code Changes:
- Modified
plugin/src/utils/worker.tsto useGeneratorinstead ofPandaContext:- Before:
loadConfigAndCreateContext()→ Creates fullPandaContext - After:
loadConfig()+new Generator()→ Creates minimal context
- Before:
isValidFile needed to be adapted. It now:
- Gets the include and exclude patterns from config ( e.g.
['src/**/*.{ts,tsx}']) - Convert the file path to be relative to the config directory
- Use
micromatchto check if the path matches the patterns directly (Complexity O(1))
Performance Impact
Tested on a large scale repository with TIMING=1 npx eslint --fix someFile
Before
Rule | Time (ms) | Relative
:---------------------------------------|----------:|--------:
@pandacss/file-not-included | 12138.285 | 98.9%
After
Rule | Time (ms) | Relative
:---------------------------------------|----------:|--------:
@pandacss/file-not-included | 1154.767 | 90.9%
-> perf gain is ~10x
Breaking Changes
no isValidFile should have the same behaviour
How can this change be tested
Unfortunately the tests are failing because isValidFile
with micromatch isn't working correctly with the new Generator. -> TBD