Skip to content
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

Improve performance, convert real-time scanning to ExternalAnnotator API #77

Merged
merged 2 commits into from
Dec 4, 2021

Conversation

intgr
Copy link
Collaborator

@intgr intgr commented Dec 2, 2021

Using the ExternalAnnotator API (instead of LocalInspectionTool) behaves a lot better with slow scanners like mypy and fixes reported performance problems with the plugin (fixes #43).

Following multiple successive changes to a file, LocalInspectionTool can invoke the checker for each modification from multiple threads in parallel, which can bog down the system. ExternalAnnotator cancels the previous running check (if any) before running the next one.

Modeled after com.jetbrains.python.validation.Pep8ExternalAnnotator

A few notes:

  • Inspections from ExternalAnnotator now look different.
  • Now using different HighlightSeverity levels instead of always a single one.
  • In the "Problems" window, mypy inspections can no longer be grouped by inspection type -- they always appear at the root level.
  • Intention actions ("suppress for statement" etc) no longer appear.
  • # noinspection Mypy comments no longer suppress the annotations.

Contributor checklist

  • I am using the provided codeStyleConfig.xml
  • I have tested my contribution on these versions of PyCharm/IDEA:
  • PyCharm Community 2021.2.3
  • My contribution is fully baked and ready to be merged as is
  • I ensure that all the open issues my contribution fixes are mentioned in the commit message of my first commit
    using the Fixes #1234 syntax

Description

Type of Changes

Type
🐛 Bug fix
🔨 Refactoring

Related Issue

Closes #43

@leinardi
Copy link
Owner

leinardi commented Dec 2, 2021

Oh wow this seems really interesting! Today I can't check it but I'll try to do it tomorrow, thanks a lot!

@leinardi
Copy link
Owner

leinardi commented Dec 3, 2021

Hi @intgr, I tested your branch and it seems to work fine!

I have some questions:

Inspections from ExternalAnnotator now look different

What does it mean that they look different? Because of the different severity levels?

In the "Problems" window, mypy inspections can no longer be grouped by inspection type -- they always appear at the root level.

I also don't get this: form what I saw the "Problems" window before and after your changes looks the same, beside the different severity level (at least with the project I'm testing):
image
image

Where can I find this "grooping by inspection type" that you say is not available anymore?

Finally, I saw that this is not checked:
image
is something else missing?

@intgr
Copy link
Collaborator Author

intgr commented Dec 4, 2021

Some screenshots to illustrate the differences:

In the "Problems" window, mypy inspections can no longer be grouped by inspection type -- they always appear at the root level.

Before After
image image

Inspections from ExternalAnnotator now look different
What does it mean that they look different? Because of the different severity levels?

Yeah, the styles associated with the new severity levels are different.

Before After
image image

Finally, I saw that this is not checked: [...] is something else missing?

Not that I know of. I just want to do some additional testing and review myself before I'm confident in this.

@intgr
Copy link
Collaborator Author

intgr commented Dec 4, 2021

Oh one more thing, the intention actions to suppress Mypy errors, disable inspection etc, is no longer available, and PyCharm suppression syntax is ignored.

Before: (this option is no longer available)

image

After: (noinspection comment ignored)

image

I haven't checked how difficult it would be to add back support for this. I guess there are some users relying on this feature. What do you think?

Although it would be better to generate the mypy-native # type: ignore comments instead.

@intgr
Copy link
Collaborator Author

intgr commented Dec 4, 2021

There's also this from comment from JetBrains developers: https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000691050/comments/115000579464

we think of inspections as something which can be disabled, annotations - something which can't, something like compiler errors.

Considering that, the LocalInspectionTool API sounds like a better fit in theory. But fixing the performance issues I think outweighs any argument from purism. Even JetBrains keeps breaking this rule with PEP 8 and TypeScript inspections. I think it's just bad design to have so different APIs for this similar functionality. I have lots of other gripes about the API design as well, but there's nothing we can do about it really. :)

@leinardi
Copy link
Owner

leinardi commented Dec 4, 2021

I haven't checked how difficult it would be to add back support for this. I guess there are some users relying on this feature. What do you think?

Although it would be better to generate the mypy-native # type: ignore comments instead.

Yeah this is not be best but, as you said, would be better to use the mypy ignore comments.

public HighlightSeverity getHighlightSeverity() {
switch (severityLevel) {
case ERROR:
return HighlightSeverity.ERROR;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realize this before, but I could switch all inspections to HighlightSeverity.WARNING to retain the previous style (yellow background).

image

But I've grown to like the red squiggly underline look. It's also familiar to users of IDEA TypeScript integration. I'd keep it HighlightSeverity.ERROR personally.

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I totally forgot that severities are configurable in the inspection profile. I suppose using that is preferable. We can revisit this logic in another PR.

image

@intgr intgr force-pushed the convert-to-ExternalAnnotator-api branch 2 times, most recently from 1b72306 to ce8e226 Compare December 4, 2021 14:10
intgr added 2 commits December 4, 2021 18:03
Using the `ExternalAnnotator` API (instead of `LocalInspectionTool`) behaves a lot better with slow scanners like mypy and fixes reported performance problems with the plugin (fixes leinardi#43).

Following multiple successive changes to a file, `LocalInspectionTool` can invoke the checker for each modification from multiple threads in parallel, which can bog down the system. `ExternalAnnotator` cancels the previous running check (if any) before running the next one.

Modeled after `com.jetbrains.python.validation.Pep8ExternalAnnotator`
@intgr intgr force-pushed the convert-to-ExternalAnnotator-api branch from 0df2c86 to 27ec03c Compare December 4, 2021 16:03
@intgr
Copy link
Collaborator Author

intgr commented Dec 4, 2021

Other than the shortcomings I pointed out in comments and bikeshedding about severity levels, this PR is ready.

  • In the "Problems" window, mypy inspections can no longer be grouped by inspection type -- they always appear at the root level.
  • Intention actions ("suppress for statement" etc) no longer appear.
  • # noinspection Mypy comments no longer suppress the annotations.

@intgr intgr marked this pull request as ready for review December 4, 2021 16:37
@leinardi
Copy link
Owner

leinardi commented Dec 4, 2021

Nice! Would it be OK for you if I add you to the Acknowledge section and to the changelog for your contribution to the project?

@leinardi leinardi merged commit 6062726 into leinardi:master Dec 4, 2021
@intgr
Copy link
Collaborator Author

intgr commented Dec 4, 2021

Yes of course. Thanks :)

@leinardi
Copy link
Owner

leinardi commented Dec 4, 2021

And do you think a new release can already be made or do you have other changes you want to submit before the next release?

@intgr
Copy link
Collaborator Author

intgr commented Dec 4, 2021

I'm looking into how difficult it would be to create an intention for generating # type: ignore comments. If it's not done by tomorrow, it's probably worth releasing without it.

@leinardi
Copy link
Owner

leinardi commented Dec 6, 2021

Hi @intgr, unfortunately the review process failed due to this error:
image
This AnnotationBuilder class seems to not be available on any version prior 2020.1.4:
image

Shall we just drop those version and change the sinceBuild to 201.8743 or do you have any other suggestion?

@intgr
Copy link
Collaborator Author

intgr commented Dec 6, 2021

Hi! There was an alternative API AnnotationHolder.createAnnotation (instead of newAnnotation()). But that one was marked deprecated.

But I don't think it's common for people to use IDEs that are more than a year old. Personally I wouldn't bother with compatibility.

@leinardi
Copy link
Owner

leinardi commented Dec 6, 2021

Yeah, CheckstyleIDEA is also supporting only recent IDE versions: https://github.com/jshiell/checkstyle-idea/blob/main/src/main/resources/META-INF/plugin.xml#L19

I'll drop everything pre 2020 👍

@leinardi
Copy link
Owner

leinardi commented Dec 7, 2021

Version 0.12.1 is out 🎉
https://plugins.jetbrains.com/plugin/11086-mypy/versions/stable/148936

@intgr
Copy link
Collaborator Author

intgr commented Dec 7, 2021

Cool, thanks!

Unfortunately because the 0.12.0 version is hidden, the original release notes aren't visible there. :)

@leinardi
Copy link
Owner

leinardi commented Dec 7, 2021

Oh that's a shame, I never had a plugin rejection before so I was not aware of this, sorry :(

intgr added a commit that referenced this pull request Feb 19, 2022
This was briefly discussed in #77 (comment) but reverted from that MR.

I have found that separating mypy inspections from PyCharm's own type checker is helpful, because PyCharm is more prone to false positives.

It's also familiar to users of IDEA TypeScript integration.
intgr added a commit to intgr/mypy-pycharm that referenced this pull request Feb 19, 2022
This was briefly discussed in leinardi#77 (comment) but reverted from that MR.

I have found that separating mypy inspections from PyCharm's own type checker is helpful, because PyCharm is more prone to false positives.

It's also familiar to users of IDEA TypeScript integration.
bigpeaches added a commit to bigpeaches/mypy-pycharm that referenced this pull request Dec 26, 2022
This was briefly discussed in leinardi/mypy-pycharm#77 (comment) but reverted from that MR.

I have found that separating mypy inspections from PyCharm's own type checker is helpful, because PyCharm is more prone to false positives.

It's also familiar to users of IDEA TypeScript integration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants