Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dobos opened this issue May 26, 2025 · 3 comments
Open
Assignees

Comments

@dobos
Copy link

dobos commented May 26, 2025

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
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?

@dobos
Copy link
Author

dobos commented May 26, 2025

The culprit can be the variables window (auto-watch). I've tried hiding it but it didn't help.

@eleanorjboyd eleanorjboyd transferred this issue from microsoft/vscode-python-debugger May 27, 2025
@connor4312
Copy link
Member

connor4312 commented May 27, 2025

pydevd warning: Computing repr of d (defaultdict) was slow (took 42.36s)

This looks like it's on the Python debugger side @eleanorjboyd

If there is renderer issues: VS Code and DAP support paginating arrays via indexedVariables, I recommend the Python debugger adopt this if it hasn't already to avoid slowdowns.

@eleanorjboyd
Copy link
Member

Thanks Connor for taking a look.

Ill investigate this @dobos, one question; if you don't run "len(d) from the debug console after the breakpoint is hit" do you still see the pydevd warning? Trying to understand if you are saying the calculation is done by the variables window or only once you take the action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants