microsoft / PTVS

Python Tools for Visual Studio
https://aka.ms/PTVS
Apache License 2.0
2.52k stars 673 forks source link

Loading is extremely slow when using mixed code debugging #7863

Closed chentasker closed 1 month ago

chentasker commented 3 months ago

Describe your question I have a c++ project that compiles to a dll, and a python script that loads it (using ctypes). My python script is quite heavy, with a lot of packages imported. I want to use VS to debug the c++ code (I don't care if Python breakpoints will be hit or not). The problem is, when I start to debug, it takes a lot of time (~5-10 minutes) to start debugging. In this time, I see a lot of messages like this on the output: 'python.exe' (Python): Loaded D:\Python\Python39\Lib\site-packages\pandas/_version_meson.py'. Module was built without symbols. My machine is not connected to the internet, so this whole process is kind of a mess because I can't download debug symbols when installing python. I installed python with the debug information on a different machine, and transferred it to mine. When installing python without the debug information it works fine and the loading is fast, but the window that asks for Python Symbols always pops up and it is annoying.

What have you tried? I've found some similar issues online but no solution. I checked and unchecked a lot of flags in Tools -> Options -> Debugging (sorry that I don't remember which ones). I also tried to remove the debug pdb files and other related files one by one.

Additional context I'm using python 3.9. Again, I don't care if python breakpoints will be hit or not, so a workaround that doesn't stop on python breakpoint is fine by me.

StellaHuang95 commented 3 months ago

Since it's debugging related, @int19h might know.

int19h commented 3 months ago

There's no such thing as debug symbols for Python modules. However, VS itself is not aware of it, so when we report a loaded Python module to it without associated symbol information, you get this warning. It's not indicative of any problem as such.

This problem usually manifests when there's a lot of Python code objects being created as modules get loaded (which usually corresponds to lots of modules or to very large modules). The mixed-mode debugger has an internal breakpoint every time a new code object instance is created, which basically means every time def, class, or lambda is executed (some other things can also create code objects depending on Python version, e.g. comprehensions). Every time that is hit, the process is paused briefly and then resumed. For packages with lots of small functions - of which Pandas is one particularly extreme example - those brief pauses can add up to noticeable slowdowns.

See https://github.com/microsoft/PTVS/issues/4929 for more discussion of this.

chentasker commented 3 months ago

Thanks for the fast response. So I understand there's no way improve the speed right now? Or prevent the window that asks for symbols from popping when the the python39.pdb file doesn't exist?

int19h commented 3 months ago

Sorry, I missed the part where you don't intend to be debugging Python. If that is the case, you should just disable Python debugging in your C++ project settings (or if you're doing attach, make sure that you only have "Native" selected under Code Type, not "Python"). This should then take care of both issues.

chentasker commented 3 months ago

Sorry, I missed the part where you don't intend to be debugging Python. If that is the case, you should just disable Python debugging in your C++ project settings (or if you're doing attach, make sure that you only have "Native" selected under Code Type, not "Python"). This should then take care of both issues.

How do I disable Python debugging? How will it work if I'm running the python script and not the C++ project.

int19h commented 3 months ago

If you're using a Python project in VS as an entrypoint, that is indeed not an option. However, since you intend to do C++ debugging only, I would suggest creating a dummy C++ project and editing its debugging settings so that it points at python.exe as the binary to debug, and add command line args so that it runs your Python script. That should give you pure C++ debugging experience.

github-actions[bot] commented 1 month ago

This issue was closed because it has been stalled for 30 days with no activity. If the issue still persists, please reopen with the information requested. Thanks.