简体   繁体   English

为什么迭代器在 VS2010 中导致调试非常缓慢,即使 _HAS_ITERATOR_DEBUGGING、_SECURE_SCL、_SECURE_SCL_THROWS 设置为 0

[英]Why are iterators causing very slow debugging in VS2010 even with _HAS_ITERATOR_DEBUGGING, _SECURE_SCL, _SECURE_SCL_THROWS set to 0

I've been trying to track down why it takes so long to debug our program when in debugging mode.我一直在试图找出为什么在调试模式下调试我们的程序需要这么长时间。 After using xperf to see what the stacks looked like it was obvious that we were spending a huge amount of our time in the iterator and the STL containers.在使用 xperf 查看堆栈的样子后,很明显我们在迭代器和 STL 容器上花费了大量时间。 I googled this for awhile and found the options我在谷歌上搜索了一会儿,找到了选项

_HAS_ITERATOR_DEBUGGING=0
_SECURE_SCL=0
_SECURE_SCL_THROWS=0

And I set all of those in code with a #define我用#define 在代码中设置了所有这些

#define _HAS_ITERATOR_DEBUGGING 0
#define _SECURE_SCL 0
#define _SECURE_SCL_THROWS 0

But that didn't seem to work, so then I tried it using the preprocessor definitions inside of the visual studio project, but that still didn't seem to help.但这似乎不起作用,所以我尝试使用 visual studio 项目中的预处理器定义来尝试它,但这似乎仍然没有帮助。

I've tried just about every permutation I can think of, including setting them in headers, and after all the includes, but no matter what I do, I'm not seeing a performance increase while debugging.我已经尝试了几乎所有我能想到的排列,包括将它们设置在标题中,以及在所有包含之后,但无论我做什么,我在调试时都没有看到性能提升。 To give an example, when running in release mode this series of operations takes about 140 seconds.举个例子,在release模式下运行这一系列操作大约需要140秒。 In debug mode it takes a little over 2,400 seconds.在调试模式下,它需要 2,400 多秒。 Roughly 17-18 fold increase in processing time.处理时间大约增加 17-18 倍。

Some additional information, the process that hosts these C++ dll's is a C# .net 4 process, and I enabled unmanaged code debugging.一些附加信息,承载这些 C++ dll 的进程是一个 C# .net 4 进程,我启用了非托管代码调试。 Basically all the process does it load up the DLLs for us.基本上所有的过程都会为我们加载 DLL。 All the real work is done in the c++ code.所有真正的工作都在 c++ 代码中完成。

I included the full compiler command line below.我在下面包含了完整的编译器命令行。

/I"..\CommonInclude" /Zi /nologo /W4 /WX /Od /Oy- /D "_CRT_SECURE_NO_WARNINGS" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_USRDLL" /D "ENGINE_EXPORTS" /D "_HAS_ITERATOR_DEBUGGING=0" /D "_SECURE_SCL=0" /D "_SECURE_SCL_THROWS=0" /D "_VC80_UPGRADE=0x0710" /D "_WINDLL" /D "_MBCS" /Gm- /EHa /MDd /GS /fp:precise /Zc:wchar_t- /Zc:forScope /GR /Yu"StdAfx.h" /Fp".\Debug/Foo.pch" /Fa".\Debug/" /Fo".\Debug/" /Fd".\Debug/" /Gd /analyze- /errorReport:queue /EHa -Zm350 /MP3 

Any ideas why this would be as slow as it is?任何想法为什么会这么慢?

Based on your description, this jumps out immediately:根据您的描述,这会立即跳出:

I've been trying to track down why it takes so long to debug our program when in debugging mode .我一直在试图找出为什么在调试模式下调试我们的程序需要这么长时间。 After using xperf to see what the stacks looked like it was obvious that we were spending a huge amount of our time in the iterator and the STL containers .在使用 xperf 查看堆栈的样子后,很明显我们在迭代器和STL 容器上花费了大量时间。

If you use the node-based containers (eg, map , set , unordered_map , unordered_set , multimap , multiset , list , etc.), and run from the debugger, you may encounter issues that stem from those containers allocating a ton of objects with small sizes.如果您使用基于节点的容器(例如mapsetunordered_mapunordered_setmultimapmultisetlist等),并从调试器运行,您可能会遇到这些容器分配大量对象的问题小尺寸。 When you run an application from the debugger in Windows, the OS switches the process heap to the debug heap.当您从 Windows 中的调试器运行应用程序时,操作系统会将进程堆切换到调试堆。 If you have many node based containers under load, freeing them will take up a lot of time with the debug heap.如果负载下有许多基于节点的容器,释放它们将占用调试堆的大量时间。

A simple fix is to disable the debug heap by adding the following to the Environment section of the debugging options: _NO_DEBUG_HEAP=1一个简单的解决方法是通过将以下内容添加到调试选项的环境部分来禁用调试堆: _NO_DEBUG_HEAP=1

That disables the debug heap.这会禁用调试堆。

One thing that makes a huge difference is that by default functions are not inlined in debug mode.造成巨大差异的一件事是默认情况下函数不会在调试模式下内联。 That adds a lot of time to code using many small accessor functions.这为使用许多小访问器函数的代码增加了大量时间。

I have programs where the difference between debug and release mode is a factor 100+, without depending on iterators.我的程序在不依赖于迭代器的情况下,调试模式和发布模式之间的差异是 100 倍以上。

A couple of things to try:要尝试的几件事:

  • Use a profiler, eg the free AMD CodeAnalyst as it will give you callstacks and is generally a lot easier to use than Xperf.使用分析器,例如免费的AMD CodeAnalyst ,因为它会为您提供调用堆栈,并且通常比 Xperf 更容易使用。 Even though you're dealing with debug code you may still find some hotspots即使您正在处理调试代码,您仍然可能会发现一些热点
  • Create a release build with optimisations switched off (you could create a separate configuration for this).创建一个关闭优化的发布版本(您可以为此创建一个单独的配置)。 This will turn off the iterator debugging (in case that is the cause of your slowdown), but may give a lot more useful debugging information than a raw release build.这将关闭迭代器调试(如果这是导致速度变慢的原因),但可能会提供比原始发布版本更有用的调试信息。 Check that the option to Omit Frame Pointers is enabled检查是否启用了省略帧指针的选项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM