Short solutions of 2021

Back to Blog

CMake RelWithDebInfo slower than Release

07.02.2021

Problem

CMake RelWithDebInfo build mode results in lower performance than Release builds (at least under Visual Studio).

Cause

Under Visual Studio, CMake forces the flag /Ob1 under RelWithDebInfo, while it uses the flag /Ob2 under Release. From Visual Studios [documentation]

Flag Description
/Ob1 Allows expansion only of functions marked inline, __inline, or __forceinline, or in a C++ member function defined in a class declaration.
/Ob2 The default value under /O1 and /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.

Solution

Force the flag /Ob2 under RelWithDebInfo.

Longer term solution

CMake should make /Ob2 the default under RelWithDebInfo.

Matlab access violation debugger attached

23.01.2021

Problem

After attaching Visual Studio debugger into Matlab process, you encounter

Exception thrown at 0x0000021781694610 in MATLAB.exe: 
0xC0000005: Access violation reading location 0x0000000000000008.

Solution

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.