Comments (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.
(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.
@leinardi :
This is is critical information and at least a hint should be in the settings page of the mypy plugin.
from mypy-pycharm.
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.
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":
from mypy-pycharm.
This issue has been automatically marked as stale because it has not had activity in the last 60 days.
from mypy-pycharm.
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)
- Mypy failed with code 2 HOT 1
- Add option to use mypy from project venv HOT 1
- Unable to use the plugin due to a file not found error
- Mypy failed with code 2 HOT 5
- (🐞) Doesn't detect mypy when using a poetry interpreter HOT 9
- Enabling plugin for CLion: de-prioritise presence of Python project SDK when checking `mypy` availability
- Icons not visible in new Jetbrains UI HOT 3
- "Mypy found no problems" after adding "[plugins]" part in mypy.ini HOT 5
- Support for mypy using WSL interpreter HOT 6
- MyPy crashes if file has changes not yet written to disc
- "Check project" 10× slower than running mypy CLI on all files instead HOT 6
- Harmless crash on macOS
- Scan failed due to an error
- mypy_path in the .ini file doesn't work as I expected when running checks on one file or module
- Check-* ignores exclude directive in mypy.ini
- Mypy tool window button icons missing in 2022.1 EAP HOT 3
- xxx is not a valid Python package name HOT 5
- Configure working directory/env vars when running mypy
- If mypy fails and only prints to stdout, not stderr, this leads to a cryptic event log message without details or stacktrace HOT 13
- Mypy executable is reported missing despite successful test HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mypy-pycharm.