Importing AST_NODE_TYPES from @typescript-eslint/typescript-estree is very slow #9613
Replies: 2 comments
-
What do you mean "before it is needed"?
Not going to happen. You're free to use strings if you want. The enum is there for good reason because it prevents whole classes of issues and makes things more discoverable.
You're free to restrict the module within your codebase using lint rules like Why would we change our API surface and prevent people from accessing |
Beta Was this translation helpful? Give feedback.
-
Now that you mention it, that's the best way to solve the issue: instead of using AST_NODE_TYPES, I'll use the string themselves. Theorically speaking, it is faster (although negligibly) since we don't have to access an object member. Thanks for the tip. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey maintainers,
A few days ago, while I was working on One Double Zero, I noticed that running the
version
command of the application was very slow - somewhere around half a second to get the version of the application output to the console.After investigating, I discovered that importing
AST_NODE_TYPES
from @typescript-eslint/typescript-estree was very slow - something around 350ms just to executeimport {AST_NODE_TYPES} from "@typescript-eslint/typescript-estree";
at runtime. After digging into the source code of the package, I discovered that@typescript-eslint/typescript-estree
, at some point, import the whole typescript package before it is needed - i.e. typically here, when importingAST_NODE_TYPES
, there is no need for typescript to be imported.I had to move the import of the package into the factory of my own custom parse function, and had to start importing
AST_NODE_TYPES
from@typescript-eslint/types
instead, which solved the issue...until today where I imported again and without noticingAST_NODE_TYPES
from@typescript-eslint/typescript-estree
- thank you dear IDE.I'm about to release a version that fix the issue one more time, but I'm sure that it will happen again, and I'm also sure that a lot of people are actually doing the same mistake without even noticing.
I'd like to request that either:
@typescript-eslint/typescript-estree
stops exporting AST_NODE_TYPES - to make sure that IDEs only import it from@typescript-eslint/types
type: 'WhileStatement'
), removing the dependency on an enum entirely while preserving type checking and autocompletion@typescript-eslint/typescript-estree
is importedBeta Was this translation helpful? Give feedback.
All reactions