-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(eslint-plugin): [no-misused-promises] avoid unnecessary calls to getContextualType #6193
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
fix(eslint-plugin): [no-misused-promises] avoid unnecessary calls to getContextualType #6193
Conversation
Thanks for the PR, @scottarver! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. |
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #6193 +/- ##
==========================================
+ Coverage 85.16% 91.23% +6.06%
==========================================
Files 383 366 -17
Lines 13025 12442 -583
Branches 3839 3645 -194
==========================================
+ Hits 11093 11351 +258
+ Misses 1570 780 -790
+ Partials 362 311 -51
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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.
This started out as a nice performance improvement - and now is also an unnecessary code removal and/or test expansion opportunity! Great either way 😄
👋 ping @scottarver - is this still something you have time for? No worries if not, just checking in. |
811ba41
to
d25c078
Compare
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 8797d46. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this branch ✅ Successfully ran 25 targets
Sent with 💌 from NxCloud. |
Ooh, I removed some more calls and all of the unit tests are failing... but now we've got lint failures in the project itself. So we've got to add unit tests! 🙌 https://cloud.nx.app/runs/NHi3D9Xh0H
Edit: 8797d46 ✅ |
It's worth noting that the two functions in question have different usecases. Cc @jakebailey this is an example of a piece of the TS API that isn't very clear - type vs apparent type vs instantiated type vs contextual type. I couldn't find any documentation about what to use and when. |
Truthfully I didn't even realize these APIs were available, let alone useful externally. Clearly, I'm wrong. I think someone more experienced than me will have to write out explanations of those. I'll file an issue to track this request; meant to do that post-meeting but forgot. |
PR Checklist
Overview
It appears that
returnsThenable
is faster thangetContextualType
in almost all cases.This PR only calls
getContextualType
when needed, afterreturnsThenable
returns true.I ran numbers on how often this is the case: Out of 19,425 total checks, only 96 (33+63) needed a call to
getContextualType
, this saved 19329 (17289 + 2040 ) calls togetContextualType
by short circuiting withreturnsThenable
Also of note on average,
returnsThenable
took 0.12891074558698418ms to run vsgetContextualType
taking 0.5058407855855643ms, saving 9.8 seconds.Using the chrome profiler to compare: ran with
node --inspect-brk ./node_modules/.bin/eslint src
Each check* fn has to be looked at together as a whole, in the table below on a single run it saved 1.2 seconds