Why is running attached to the debugger so slow?

后端 未结 4 890
耶瑟儿~
耶瑟儿~ 2021-01-12 15:25

What is going on that causes a debug build to be so much slower attached to the debugger compared to unattached? They are both the same exe running.

Edit: Most of th

4条回答
  •  借酒劲吻你
    2021-01-12 15:59

    If it isn't OutputDebugString or piles and piles of breakpoints slowing everything down, try these:

    • Windows debug heap - your process gets the debug heap if it is running under a debugger, no questions asked. To disable this when running under the Visual Studio debugger, visit the debugging page of the project properties and add _NO_DEBUG_HEAP=1 to the environment.

      (The Windows debug heap is a separate thing from the CRT debug heap. Your release build will get the Windows debug heap too, if it runs under a debugger.)

    • The program loads lots of DLLs that have symbols. When a DLL is loaded, Visual Studio tries to find symbols for it. If there are symbols available, this can take time. There's not much you can do about this except to rearrange your program so that it loads DLLs less often.

    • Check for any calls to IsDebuggerPresent - this can introduce arbitrary differences between running in the debugger and outside it.

    (As a final throwaway suggestion - I would also be suspicious that exceptions (whether C++ or structured) might be a bit more involved when the process is being debugged. So if your programs throws a lot, maybe that could be a bit slower when it's being debugged.)

提交回复
热议问题