Description
Before You File a Bug Report Please Confirm You Have Done The Following...
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I have searched for related issues and found none that matched my issue.
- I have read the FAQ and my problem is not listed.
Issue Description
I profiled my eslint to see what it is slow, and it lead me to @typescript-eslint/no-misused-promises
, and the culprate inside is getContextualType
it appears that returnsThenable
can be called first before getContextualType
for checkJSXAttribute
profiling a smaller component:
It looks like getContextualType
is more expensive than returnsThenable
Inside I saw that there was potential for an optimization to not call checker.getContextualType(value)
every time. I made this change locally and my lints on my big project went from ~130 seconds to ~125
There appears to be some other optimizations that can be done to calls to getContextualType
but I only looked at 1 place, and I'm not sure of the technicals of getContextualType
and returnsThenable
yet
on my large private repo, I got 4311 short circuits and 15 calls to getContextualType
. so it saved 4311
calls to getContextualType
.
I am willing to make the PR
diff --git a/packages/eslint-plugin/src/rules/no-misused-promises.ts b/packages/eslint-plugin/src/rules/no-misused-promises.ts
index b6914ae2..0e85656e 100644
--- a/packages/eslint-plugin/src/rules/no-misused-promises.ts
+++ b/packages/eslint-plugin/src/rules/no-misused-promises.ts
@@ -375,11 +375,16 @@ export default util.createRule<Options, MessageId>({
) {
return;
}
+ if(!returnsThenable(checker, value.expression)){
+ return;
+ }
const contextualType = checker.getContextualType(value);
if (
contextualType !== undefined &&
- isVoidReturningFunctionType(checker, value, contextualType) &&
- returnsThenable(checker, value.expression)
+ isVoidReturningFunctionType(checker, value, contextualType)
) {
context.report({
messageId: 'voidReturnAttribute',
Reproduction Repository Link
N/A
Repro Steps
- clone the repo
yarn install
yarn lint
- run
NODE_OPTIONS="--inspect-brk"
prefixing the eslint command - observe the slowest inside the chrome profiler
Versions
package | version |
---|---|
@typescript-eslint/eslint-plugin |
5.45.1 |
@typescript-eslint/parser |
5.45.1 |
TypeScript |
4.9.3 |
ESLint |
8.29.0 |
node |
v16.17.0 |