Skip to content
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

Ideas about how to significantly improve performance #201

Open
SukkaW opened this issue Dec 11, 2024 · 8 comments
Open

Ideas about how to significantly improve performance #201

SukkaW opened this issue Dec 11, 2024 · 8 comments
Labels
help wanted Extra attention is needed

Comments

@SukkaW
Copy link
Collaborator

SukkaW commented Dec 11, 2024

Currently, when eslint-plugin-import-x finds an import, it will resolve the real path of the module (through the eslint import resolvers), read the file, and then parse the module into the AST using the configured parsers (import-x/parser) or the default parser (ruleContext.parserPath). Then eslint-plugin-import-x tried to extract all exports/imports by walking through AST.

Parse any referenced modules are very heavy tasks, resulting eslint-plugin-import-x being slow. But if we use something like es-module-lexer or cjs-module-lexer to scan the imports/exports we skip the entire parsing-into-AST process and significantly improve performance for a few rules.

@SukkaW
Copy link
Collaborator Author

SukkaW commented Dec 11, 2024

We have es-module-lexer that works for ESM and cjs-module-lexer for CommonJS. But we still need lexers for JSX / TypeScript / TSX (or even flow). I still want TypeScript to benefit from this.

Oxc says they will have one for ESM and TypeScript/TSX, but they won't support the CJS.

And we also have rs-module-lexer @fz6m.

@SukkaW SukkaW pinned this issue Dec 11, 2024
@SukkaW SukkaW changed the title Ideas about how to significantly improve performance of some rules Ideas about how to significantly improve performance Dec 11, 2024
@silverwind
Copy link

silverwind commented Dec 11, 2024

We have es-module-lexer that works for ESM and cjs-module-lexer for CommonJS. But we still need lexers for JSX / TypeScript / TSX (or even flow). I still want TypeScript to benefit from this.

For Typescript could strip types with https://github.com/nodejs/amaro or the underlying https://swc.rs/docs/references/wasm-typescript and then pass the result to the lexers. Would be interesting to hear about the performance of that approach vs. full AST parsing.

@SukkaW
Copy link
Collaborator Author

SukkaW commented Dec 12, 2024

For Typescript could strip types with https://github.com/nodejs/amaro or the underlying https://swc.rs/docs/references/wasm-typescript and then pass the result to the lexers.

But IMHO it might not work with export =.

@privatenumber
Copy link

For TS, Oxc parser is a possible alternative to es-module-lexer

@SukkaW
Copy link
Collaborator Author

SukkaW commented Dec 27, 2024

For TS, Oxc parser is a possible alternative to es-module-lexer

Not supported, yet: oxc-project/oxc#2608 (comment)

I have already raised this to the oxc team.

@SukkaW
Copy link
Collaborator Author

SukkaW commented Dec 27, 2024

guybedford/es-module-lexer#185 is merged and released.

We can try to implement ESM and CJS scan with cjs-module-lexer and es-module-lexer. Currently, there is no good alternative for TypeScript, so TypeScript projects have to fall back to the current AST parsing.

@Samuel-Therrien-Beslogic
Copy link

Samuel-Therrien-Beslogic commented Jan 21, 2025

Not so much a "performance improvement" from the plugin. But anyone landing on this issue looking at speeding up their run can consider disabling the namespace rule.

It's not really as useful with TypeScript anyway

Edit: Answer below is what the linked issue is saying as well. I'm not posting it as a fix. It's a (hopefully temporary) workaround with an explanation for users who'd like a linting performance boost by dropping the affected rules. Until a proper solution comes around.

@SukkaW
Copy link
Collaborator Author

SukkaW commented Jan 22, 2025

Not so much a "performance improvement" from the plugin. But anyone landing on this issue looking at speeding up their run can consider disabling the namespace rule.

It's not really as useful with TypeScript anyway

Disabling import/namespace just won't help. Any rule can initiate external module parsing, and after parsing the AST will be cached (so the other rules can benefit from this).

It just so happens that import/namespace initiates most external modules to be parsed. If you disable the import/namespace rule, other rules will initiate their parsing tasks and become slower. The total lint time won't reduce by much.

The only escape is what I am proposing here, replacing external module parsing with external module lexing completely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants