CMake RelWithDebInfo build mode results in lower performance than Release builds (at least under Visual Studio).
Under Visual Studio, CMake forces the flag
/Ob1 under RelWithDebInfo, while it uses the flag
/Ob2 under Release. From Visual Studio’s [documentation]
Flag | Description
/Ob1 | Allows expansion only of functions marked
__forceinline, or in a C++ member function defined in a class declaration.
/Ob2 | The default value under
/O2. Allows the compiler to expand any function not explicitly marked for no inlining.
Since modern codebases rely heavily on inlining, using
/Ob1 instead of
/Ob2 can affect performance severely. This in conflict with the common advice that RelWithDebInfo gives you the same performance as Release, but with debug information.
Force the flag
/Ob2 under RelWithDebInfo.
CMake should make
/Ob2 the default under RelWithDebInfo.
After attaching Visual Studio debugger into Matlab process, you encounter
Exception thrown at 0x0000021781694610 in MATLAB.exe: 0xC0000005: Access violation reading location 0x0000000000000008.
This problem has been discussed here. I still don’t know what the cause of the exception is, and whether it is bad or not, but, as mentioned in the link, the debugger can be made to skip it by removing
0xC0000005: Access violation from the list of exceptions breakpoints. In Visual Studio, the breakpoint can be toggled at
Debug > Windows > Exception Settings > Win32 Exceptions.