microsoft / microsoft/vscode-python-debugger

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

未關閉
#898 12 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

triage-needed
主要語言
TypeScript
星號
181
分支
126
平均合併
2 天 3 小時
30 天內合併 PR
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. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 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 摘要。