microsoft / microsoft/vscode-python-debugger

Evaluating expression of large objects from the debug console is extremely slow

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

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

triage-needed
主要言語
TypeScript
スター
181
フォーク
126
平均マージ
2日 3時間
マージ済み PR(30日)
3

説明

I'm seeing an issue that apparently hasn't been reported yet. I have a fairly large dictionary in memory and when I want to get its length from the debug console it takes tens of seconds. Obviously, getting the repr of the dict takes that much time but I only want to get its length.

Code to reproduce:

from unittest import TestCase
from collections import defaultdict
import numpy as np
from types import SimpleNamespace

class MyTest(TestCase):
    def test_large_defaultdict(self):
        d = defaultdict(lambda: defaultdict(list))
        for k in 'abcdef':
            for l in 'ghijk':
                for i in range(10000):
                    d[k][l].append(SimpleNamespace(
                        key = k,
                        cycle = np.arange(20),
                        value = np.zeros(20)
                    ))

        pass

Set breakpoint on pass and try to evaluate len(d) from the debug console after the breakpoint is hit. This warning is printed in the console:

pydevd warning: Computing repr of d (defaultdict) was slow (took 42.36s)
Customize report timeout by setting the `PYDEVD_WARN_SLOW_RESOLVE_TIMEOUT` environment variable to a higher timeout (default is: 0.5s)

Yes, it is slow but why is repr called to print the number of items?

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

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

はじめの一歩

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

調査の方向性

test.py の再現ケースとデバッグコンソールでの len(d) の評価から始め、遅い repr に関する警告を出力するデバッガーの値解決パスを追跡します。len(d) の評価とオブジェクトの直接検査を比較し、表現が不必要に計算されている箇所を特定します。大きなオブジェクトの長さの評価で repr による遅延が発生しなくなり、その動作が回帰テストでカバーされれば完了です。

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

評価

技術スタック
python, typescript, vscode
領域
developer-experience, devtools
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

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

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