-
Notifications
You must be signed in to change notification settings - Fork 8
perf(worker): avoid accessing panda context to scan all files #291
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
perf(worker): avoid accessing panda context to scan all files #291
Conversation
| ...v9Config, | ||
| include: ['**/*'], | ||
| exclude: ['**/Invalid.tsx', '**/panda.config.ts'], | ||
| importMap: './panda', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test files import Panda artifacts from ./panda/... The generator needs this importMap to correctly identify these imports as belonging to Panda.
| ctx.getFiles = () => ['App.tsx'] | ||
| const ctx = createGeneratorContext({ | ||
| ...v9Config, | ||
| include: ['**/*'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensures that all files used in tests (e.g., App.tsx) are considered valid
| include: ['**/*'], | ||
| exclude: ['**/Invalid.tsx', '**/panda.config.ts'], | ||
| importMap: './panda', | ||
| jsxFactory: 'styled', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Th sandbox/v9/panda.config.ts sets jsxFactory to 'panda', but the tests use styled (e.g., styled.div). Overriding this to 'styled' ensures that matchImports correctly identifies styled as the JSX factory, enabling rules like no-dynamic-styling to work correctly....
| const ctx = createContext() as unknown as PandaContext | ||
| ctx.getFiles = () => ['App.tsx'] | ||
| const ctx = createGeneratorContext({ | ||
| ...v9Config, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the tests rely on the specific configuration (tokens, recipes, conditions) defined in
sandbox/v9/panda.config.ts
What kind of change does this PR introduce?
Fixes #160
The
getFiles()method is part ofPandaContextIt 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:
plugin/src/utils/worker.tsto useGeneratorinstead ofPandaContext:loadConfigAndCreateContext()→ Creates fullPandaContextloadConfig()+new Generator()→ Creates minimal contextisValidFileneeded to be adapted. It now:['src/**/*.{ts,tsx}'])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 someFileBefore
After
-> perf gain is ~10x
Breaking Changes
isValidFileshould have the same behaviourHow can this change be tested