-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Bug: no-misused-promises
rule is slow to evaluate
#10996
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
Comments
Uh oh! @benmccann, at least one image you shared is missing helpful alt text. Check your issue body to fix the following violations:
Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image. Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs.
|
Hi, please see https://typescript-eslint.io/troubleshooting/typed-linting/performance:
|
He's actually aware of that and has run this without that rule enabled and seen a speed up. Suggesting this rule is indeed slow Reopen it and we can look into it properly There are some optimisations I have in mind but I'm not at a laptop right now so will write them up once I have chance to run the repro |
Do you have benchmarks for each individual rule? |
Uh oh! @benmccann, at least one image you shared is missing helpful alt text. Check #10996 (comment) to fix the following violations:
Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image. Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs.
|
Hmmm interesting. Yeah we should look at this. |
ESLint timing information is pretty useless in terms of determining type-aware rule performance, sadly. Type information is computed lazily so that means that the first rule to request types for a particular location bears the cost of computing that type and all subsequent rules get if "for free". Based on your screenshot it looks like you're not using many type-aware lint rules - which means that To be clear: I'm not saying that the rule doesn't have a perf bug in it. I'm just saying that |
@pralkarz reported that it spends almost 3 minutes in
|
I'd like to take a deeper look at how
Could you post steps we can take to get this repo to a fully built state, please? Btw, +1 to #10996 (comment) and not posting images in general. Unless an image's alt text describes every relevant piece of information in it, a non-sighted user reading this thread would miss out. "Screenshot showing timings when no-misused-promises is disabled" doesn't say what the rules or timings are. Plus it's easier to copy & paste / generally interact with raw text. If you have a table of text to display please paste just the text or even format it as a Markdown table. |
FYI it seems to be pretty much that i feel like there's some optimisation but not sure what exactly yet for example, if you reference currently we do this for every possible call expression, which is going to be pretty slow. there must be a way we can be smarter about which ones we look up 🤔 |
See my previous comment about type information being computed lazily. TS has its own caches for types that are filled with each new call and it serves from the cache when it can. We have tried adding a cache in front of the APIs but we found there was a negligible improvement in perf (on mobile so can't dig up the PR but look for closed and unmerged PRs by Josh). If you could collate the perf trace and break it down into P50/70/95/99 then you'd likely see that there's there's a large skew in the runtime per call and most calls would be fast (if the codebase has repeated types, that is). |
it isn't to do with the type information being computed lazily unfortunately
in a CPU profile you can quite easily see that every occurrence of it takes more time than most other calls |
you can see here, every sibling entry around the same width is also a call to this is during a run on immich with everything except these rules enabled: rules: {
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-misused-promises': 'error',
'@typescript-eslint/require-await': 'error',
}, we can certainly move on from the usual "its just slow to start up". it isn't that in this case |
@43081j caaaaan you please post the CPU profile file itself? And any other files that you are referencing that we don't have ourselves please? 🙂 |
i won't have time to run it again until maybe later today or tomorrow but once i do i can try attach one. unless ben or pralkarz beat me to it |
I'm not home at the moment to share the file, but after |
|
You could try adding a global Otherwise I'd hazard a guess that each time we call |
I wonder why |
We need to do different checks to TS and get more types that it doesn't need to. For example we need to check every type to see if it is a promise by way of looking for a Often times TS can short-circuit its checks by way of simple assignability checks like "are the property names a match". It can often also short-circuit with simple TS also has access to internal APIs that we don't. For example where we call methods they can check There's also chances we're doing the wrong things and getting more types than we need. It's hard to know for sure. As one example for |
according to the TS team, it does cache the lookup per symbol at least (inside typescript) |
I'd still say that you're not wrong and we could probably see wins by doing some caching of all the functions that are at the top-level of the rule module. Many of the utils do work like iterating call signatures to figure out if a type matches some shape. But we don't need to do that every time for all types - there's likely room for caching and short-circuiting to save some time there. It would be worth someone giving it a whirl by editing your local install in your repo to see if it shifts the needle. |
I've created a |
Before You File a Bug Report Please Confirm You Have Done The Following...
Issue Description
Set
TIMING=20
in thelint
script of this repo: https://github.com/immich-app/immich/tree/main/webTook over 4 min to run while other rules completed quickly
Reproduction Repository Link
https://github.com/immich-app/immich
Repro Steps
Versions
This repo is currently on
typescript-eslint
8 as indicated below, but I've sent a PR to upgrade it to the latest v9 and it happens there as well@typescript-eslint/eslint-plugin
8.26.1
@typescript-eslint/parser
8.26.1
@typescript-eslint/scope-manager
8.26.1
@typescript-eslint/typescript-estree
8.26.1
@typescript-eslint/type-utils
8.26.1
@typescript-eslint/utils
8.26.1
TypeScript
5.7.3
ESLint
9.18.0
node
22.11.0
The text was updated successfully, but these errors were encountered: