Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@scottarver
Copy link
Contributor

PR Checklist

Overview

It appears thatreturnsThenable is faster thangetContextualType in almost all cases.
This PR only callsgetContextualType 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 togetContextualType, 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.

total time saved:  9817.560766001232{  thenableAndContextual: 33,  NotThenableAndContextual: 17289,  thenableAndNotContextual: 63,  NotThenableAndNotContextual: 2040}thenable count:  19425thenable average: 0.12891074558698418contextualType count:  19425contextualType average: 0.5058407855855643

Using the chrome profiler to compare: ran withnode --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

BeforeAfter
imageimage
 beforeafter   
checkTestConditional73.677   
checkConditional2.43.6   
checkAssignment1.72.9   
checkVariableDeclaration1160.51207.4   
checkProperty74.440.2   
checkReturnStatement9.256.1   
checkJSXAttribute2076.9754.7   
checkArguments121.6125.6   
checkSpread5.54.4 ms diffseconds
 3525.82271.9 1253.91.2539

eyal1990 and JoshuaKGoldberg reacted with thumbs up emoji
@typescript-eslint
Copy link
Contributor

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 onhttps://opencollective.com/typescript-eslint.

@nx-cloud
Copy link

nx-cloudbot commentedDec 9, 2022
edited
Loading

☁️ Nx Cloud Report

CI is running/has finished running commands for commitc02724c. 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


🟥 Failed Commands
Node 14 - nx test typescript-estree --coverage=false
nx run-many --target=lint --parallel
✅ Successfully ran 28 targets

Sent with 💌 fromNxCloud.

@netlify
Copy link

netlifybot commentedDec 9, 2022
edited
Loading

Deploy Preview fortypescript-eslint ready!

NameLink
🔨 Latest commit8797d46
🔍 Latest deploy loghttps://app.netlify.com/sites/typescript-eslint/deploys/640f8c67d239b500088d641b
😎 Deploy Previewhttps://deploy-preview-6193--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to yourNetlify site settings.

@scottarverscottarver changed the titleavoid unnecessary calls to getContextualTypefir(eslint-plugin): avoid unnecessary calls to getContextualTypeDec 9, 2022
@scottarverscottarver changed the titlefir(eslint-plugin): avoid unnecessary calls to getContextualTypefix(eslint-plugin): avoid unnecessary calls to getContextualTypeDec 9, 2022
@codecov
Copy link

codecovbot commentedDec 9, 2022
edited
Loading

Codecov Report

Merging#6193 (b039619) intomain (2b2a075) willincrease coverage by6.06%.
The diff coverage is63.63%.

❗ Current headb039619 differs from pull request most recent head8797d46. Consider uploading reports for the commit8797d46 to get more accurate results

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
FlagCoverage Δ
unittest91.23% <63.63%> (+6.06%)⬆️

Flags with carried forward coverage won't be shown.Click here to find out more.

Impacted FilesCoverage Δ
...ges/eslint-plugin/src/rules/no-misused-promises.ts95.63% <63.63%> (-2.85%)⬇️

... and65 files with indirect coverage changes

Copy link
Member

@JoshuaKGoldbergJoshuaKGoldberg left a 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 😄

@JoshuaKGoldbergJoshuaKGoldberg added the awaiting responseIssues waiting for a reply from the OP or another party labelDec 12, 2022
@JoshuaKGoldberg
Copy link
Member

👋 ping@scottarver - is this still something you have time for? No worries if not, just checking in.

@JoshuaKGoldbergJoshuaKGoldberg self-requested a reviewMarch 13, 2023 05:32
@nx-cloud
Copy link

nx-cloudbot commentedMar 13, 2023
edited
Loading

☁️ Nx Cloud Report

CI is running/has finished running commands for commit8797d46. 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 💌 fromNxCloud.

@JoshuaKGoldberg
Copy link
Member

JoshuaKGoldberg commentedMar 13, 2023
edited
Loading

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

/home/runner/work/typescript-eslint/typescript-eslint/packages/eslint-plugin/src/rules/adjacent-overload-signatures.ts  172:18  error  Promise-returning function provided to property where a void return was expected  @typescript-eslint/no-misused-promises  173:16  error  Promise-returning function provided to property where a void return was expected  @typescript-eslint/no-misused-promises  174:22  error  Promise-returning function provided to property where a void return was expected  @typescript-eslint/no-misused-promises  175:22  error  Promise-returning function provided to property where a void return was expected  @typescript-eslint/no-misused-promises  176:24  error  Promise-returning function provided to property where a void return was expected  @typescript-eslint/no-misused-promises  177:23  error  Promise-returning function provided to property where a void return was expected  @typescript-eslint/no-misused-promises/home/runner/work/typescript-eslint/typescript-eslint/packages/eslint-plugin/src/rules/ban-types.ts  203:41  error  Promise-returning function provided to variable where a void return was expected  @typescript-eslint/no-misused-promises/home/runner/work/typescript-eslint/typescript-eslint/packages/eslint-plugin/src/rules/block-spacing.ts...

Edit:8797d46

@JoshuaKGoldbergJoshuaKGoldberg changed the titlefix(eslint-plugin): avoid unnecessary calls to getContextualTypefix(eslint-plugin): [no-misused-promises] avoid unnecessary calls to getContextualTypeMar 13, 2023
@JoshuaKGoldbergJoshuaKGoldberg merged commit745cfe4 intotypescript-eslint:mainMar 13, 2023
@bradzacher
Copy link
Member

It's worth noting that the two functions in question have different usecases.returnsThenable uses the "apparent type" which is sometimes different to the contextual type (I believe??)

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.

@jakebailey
Copy link
Collaborator

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.

bradzacher reacted with heart emoji

@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsMar 21, 2023
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@JoshuaKGoldbergJoshuaKGoldbergAwaiting requested review from JoshuaKGoldberg

Assignees

No one assigned

Labels

awaiting responseIssues waiting for a reply from the OP or another party

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Enhancement: no-misused-promises small performance improvement, avoiding unnecessary call to getContextualType

4 participants

@scottarver@JoshuaKGoldberg@bradzacher@jakebailey

[8]ページ先頭

©2009-2025 Movatter.jp