python / python/mypy

`dmypy` - poor performance when a lot of possibly unrelated errors

Open
#14,474 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-daemon
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report

The dmypy daemon will experience poor performance if there are a lot of files with errors, even if only a single file is updated.

To Reproduce

Create a ball of mud with errors. This script requires some tweaking to really bring out the issue but its a good starting point:

https://github.com/JamesHutchison/mypy/blob/dmypy-update-perf/ball_of_mud/generate_ball_of_mud.py

The performance deficit is proportionate to the number of failing files.

Expected Behavior

dmypy is always fast for small changes

Actual Behavior

dmypy is slow.

Your Environment

  • Mypy version used: 0.991

Why is this important?

When converting a large repo to mypy you will have a lot of failing files at first and you cannot use --follow-imports=silent

Notes

The cause appears to be this code:

https://github.com/python/mypy/blob/master/mypy/server/update.py#L847

From what I can tell, it looks like dmypy relies on files failing their imports to know to revisit them later. This appears to also be the reason that you cannot use --follow-imports=silent with dmypy.

For example, when --follow-imports=error:

  • File A is built, and File A imports file B. File A gets errors about B not existing.
  • File B is built
  • File A gets built again, but this time B is cached (or loaded, or whatever) and no longer fails import

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with mypy/server/update.py around line 847 and reproduce the slowdown using the ball_of_mud/generate_ball_of_mud.py script linked in the issue. Investigate why many failing files are revisited when only one file changes; done means dmypy remains fast for small changes despite unrelated errors, while preserving the relevant import behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.