Giter Site home page Giter Site logo

Comments (7)

paranoidi avatar paranoidi commented on May 29, 2024 7

It looks like the plugin is spawning a lot of duplicate processes. When I observe htop in second screen while editing a file it spawns up to 10 identical process for the same file.

It would also be VERY beneficial if the plugin would support using dmypy daemon, which is significantly faster on subsequent executions and uses much less resources. I tried to create a hacky wrapper script to get it running via that but it did not work.

from mypy-pycharm.

intgr avatar intgr commented on May 29, 2024 2

(Initially it was my assumption that the plugin could run mypy on saved files only. That ended up not being true -- if there are unsaved changes to a file, the mypy plugin will write to a temporary file and run mypy with that file)

The plugin integrates with IntelliJ via the LocalInspectionTool API, where IntelliJ calls checkFile() to analyse a given file whenever it wants to, which is subject to some heuristics. This often happens even while typing, with unsaved modifications to the file.

IntelliJ can call checkFile() in parallel on multiple threads -- on different versions of the file. And the mypy plugin currently faithfully tries to spawn a new mypy process every time. With increased load, successive runs are even slower, leading to this pathological behavior.

This is very wasteful on IntelliJ's part, plugins are called to calculate inspections for file versions that will never be seen by the user.

There doesn't seem to be any obvious way to make IntelliJ limit those parallel checkFile() calls, but maybe I'm missing something. I guess we could implement throttling within the mypy plugin itself. I wonder whether other plugin authors have already solved this problem.

(I also noticed that sometimes checkFile() is called multiple times when only one change was made. This can be easily detected via psiFile.getModificationStamp() and we can return cached results in that case.)

from mypy-pycharm.

spacemanspiff2007 avatar spacemanspiff2007 commented on May 29, 2024 1

@leinardi :
This is is critical information and at least a hint should be in the settings page of the mypy plugin.

from mypy-pycharm.

intgr avatar intgr commented on May 29, 2024 1

After searching the web and digging around in IntelliJ source code, I discovered that there's another API called ExternalAnnotator, which seems like a better fit for this purpose:

The external annotator is expected to be slow and is started after the regular annotator has completed its work.

After migrating to this API and removing the use of Async.asyncResultOf, IntelliJ now cancels any previous background inspection jobs when spawning a new one. Not totally sure how the mechanism works, but the ProcessCanceledException is thrown.

There are some dowsides compared to LocalInspectionTool, however. According to https://consulo.dev/reference_guide/custom_language_support/code_inspections_and_intentions/ LocalInspectionTool adds:

  • supports batch analysis of code (through the Analyze | Inspect Code... action)
  • the possibility to turn off the inspection (globally or by suppressing them on various levels)
  • ability to configure the inspection options.

Anyway the code is still a very dirty proof of concept, but can be found at https://github.com/intgr/mypy-pycharm/pull/1/files

from mypy-pycharm.

leinardi avatar leinardi commented on May 29, 2024

Hi Simon,
I have retested it to be sure and I can confirm that, if you disable the Mypy inspection from your IDE settings, you should have no performance impact at all since it won't run.
Just open the IDE Settings/Preferences then search for "Inspection", look for "Mypy" and remove the check from the entry "Mypy real-time scan":
image

from mypy-pycharm.

stale avatar stale commented on May 29, 2024

This issue has been automatically marked as stale because it has not had activity in the last 60 days.

from mypy-pycharm.

intgr avatar intgr commented on May 29, 2024

I'm having a try at debugging and fixing this issue.

If anyone already has some pointers for why this occurs or how to fix it, please reply here.

from mypy-pycharm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.