python / python/mypy

Daemon performance seems slow

オープン
#16,745 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

performance topic-daemon
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

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
  1. Is this oscillation in run time (seen on the first test) expected?
  2. Is it expected to see a second run be much slower than subsequent runs on the same file if nothing is modified?
  3. Is there anything I can do to speed this up, other than setting follow-imports to skip?

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

提供されたタイミングスクリプトから始め、scratch.py に追記する場合としない場合で、dmypy run scratch.py を繰り返し実行して比較します。daemon の初回実行時、変更のない実行時、ファイルを変更した実行時の時間を調査します。完了の条件は、振動の理由を説明し、follow-imports=skip 以外にチェック時間を短縮できるサポートされた方法を特定することです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
devtools, performance
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。