I had an issue that a Win32 application has huge performance difference between debug and release build. It takes 20 sec for release, while 6 min for debug build to initialize the application. This is painful since when debugging, it always takes 6 min to proceed the initialization before starting doing anything. So I am looking for a way to tune the performance in debug build.
After running profiler, I found below code is the hot-spot.
class CellList {
std::vector<CellPtr>* _cells;
iterator begin() { return (*_cells).begin(); }
iterator end() { return (*_cells).end(); }
reverse_iterator rbegin() { return (*_cells).rbegin(); }
reverse_iterator rend() { return (*_cells).rend(); }
...
}
CellList _cellList = ...;
for (CellList::iterator itr = _cellList.begin(), end = _cellList.end(); itr < end; ++itr) {
Cell* cell = *itr;
if (cell->getFoo()) cell->setBar(true);
else cell->setBar(false);
}
for (CellList::iterator itr = _cellList.rbegin(), end = _cellList.rend(); itr < end; ++itr) {
Cell* cell = *itr;
if (cell->getFoo2()) cell->setBar2(true);
else cell->setBar2(false);
}
And these are the hot-spot in the time-base profile result.
std::operator< <std::_Vector_iterator<Cell *,std::allocator<Cell *> >,std::_Vector_iterator<Cell *,std::allocator<Cell *> > >
std::_Vector_const_iterator<Cell *,std::allocator<Cell *> >::operator<
std::reverse_iterator<std::_Vector_iterator<Cell *,std::allocator<Cell *> > >::operator*
std::reverse_iterator<std::_Vector_const_iterator<Cell *,std::allocator<Cell *> > >::reverse_iterator<std::_Vector_const_iterator<Cell *,std::allocator<Cell *> > ><std::_Vector_iterator<Cell *,std::allocator<Cell *> > >
I guess it’s the iterator operation not being inlined and causes this huge difference. Is there any way to improve this? I can debug in release mode as long as it’s still possible to step line by line in the source code and check all the variable values.
The difference is normal. What’d I’d do is place
around the methods you want to check, and keep the rest of the build in release mode.