Daemon performance seems slow
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
I've written a simple little timing script:
import os
from timing import TicToc # our own timing context
with TicToc('stop daemon'):
os.system('dmypy stop')
for _ in range(10):
with TicToc('Run on scratch'):
os.system('dmypy run scratch.py > boo.txt')
with TicToc('Modify scratch'):
with open('scratch.py', 'a') as f:
f.write('\n\nx: int = 5\n')
scratch.py is a file in a repo with ~100k lines of code. It's a work in progress as far as typing goes; boo.txt ends with Found 2587 errors in 143 files (checked 1 source file)
The intention of the script is to simulate me working on code, e.g. scratch.py, and having type checking run frequently (e.g. every time I save the file).
With default mypy (1.8.0) settings, I get this:
Daemon stopped
[stop daemon] 0.161 seconds
[Run on scratch] 33.603 seconds
[Modify scratch] 0.002 seconds
[Run on scratch] 7.247 seconds
[Modify scratch] 0.002 seconds
[Run on scratch] 3.549 seconds
[Modify scratch] 0.001 seconds
[Run on scratch] 7.029 seconds
[Modify scratch] 0.002 seconds
[Run on scratch] 3.721 seconds
[Modify scratch] 0.001 seconds
[Run on scratch] 6.860 seconds
[Modify scratch] 0.002 seconds
[Run on scratch] 3.705 seconds
[Modify scratch] 0.001 seconds
[Run on scratch] 8.777 seconds
[Modify scratch] 0.002 seconds
[Run on scratch] 3.623 seconds
[Modify scratch] 0.001 seconds
[Run on scratch] 6.872 seconds
[Modify scratch] 0.002 seconds
In other words, the time it takes to check this one file (once the daemon has started) oscillates between ~4 seconds and ~7 seconds, just by adding a single line to scratch.py each time.
Without modifying scratch.py between runs, I get this:
Daemon stopped
[stop daemon] 0.161 seconds
[Run on scratch] 33.603 seconds
[Run on scratch] 4.002 seconds
[Run on scratch] 0.369 seconds
[Run on scratch] 0.364 seconds
[Run on scratch] 0.364 seconds
[Run on scratch] 0.371 seconds
[Run on scratch] 0.364 seconds
[Run on scratch] 0.366 seconds
[Run on scratch] 0.362 seconds
[Run on scratch] 0.362 seconds
- Is this oscillation in run time (seen on the first test) expected?
- Is it expected to see a second run be much slower than subsequent runs on the same file if nothing is modified?
- Is there anything I can do to speed this up, other than setting
follow-importstoskip?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided timing script and compare repeated dmypy run scratch.py executions with and without appending to scratch.py. Investigate the daemon's first-run, unchanged-run, and modified-file timings; done means explaining the oscillation and identifying any supported way to reduce the checking time beyond follow-imports=skip.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100