Safe but slow STL
Recently we have implemented a parser to read / write triangulated surface data into a file. The parser works perfect in release mode (compiled by using Visual Studio 2008), but becomes tremendously slow in debug mode. This started causing the huge loss in productivity of the team in debugging – as now just reading a geometry file in the software takes around 6 minutes compared to few seconds in release mode. This remained a problem for quite some time until we have discovered that its standard template library (STL) implementation that was causing this slowness.
The STL implementation on Windows platform has concepts of Checked Iterator and Debug Iterator These safe iterator helps in detecting following kind of problems in iterator usage:
· Using an iterator that has been invalidated by collection modification
· Using an iterator to attempt to access an element outside the bounds of a container
Refer http://msdn.microsoft.com/en-us/library/aa985872%28v=VS.90%29.aspx for detail.
We observed that the implementation of safe iterator (especially the debug iterator) was making the overall software very slower. And, in the debug mode, the Checked and Debug iterator code is remains switched on by default. We disabled the safe iterator by changing the value of pre-processor _SECURE_SCL and _HAS_ITERATOR_DEBUGGING to 0.
In "C/C++ | Preprocessor" Add ;_SECURE_SCL=0;_HAS_ITERATOR_DEBUGGING=0 to Pre-processor Definitions for both Debug and Release. As a rule, expert suggests to set identical value for these pre-processor within a translation unit and a DLL.
With this change, the team was able to regain the productivity in normal debugging purposes.
Safe but slow STL
Reviewed by Sourabh Soni
on
Sunday, November 14, 2010
Rating:
No comments