Mapping check() to assume()

I am using check() quite a lot in my code base, for about everything - null pointers, bounds checking etc.

As an optimization, couldn’t the check() be mapped to assume() in Development configuration? Or is it too hazardous?

Hey G4m4,

Thanks for your suggestion. According to MSDN:

“A program must not contain an invalid __assume statement on a reachable path. If the compiler can reach an invalid __assume statement, the program might cause unpredictable and potentially dangerous behavior. (…)
Use __assume in an ASSERT only when the assert is not recoverable. Do not use __assume in an assert for which you have subsequent error recovery code because the compiler might optimize away the error-handling code.”

We’d have to check every case to see if we don’t remove any code by accident. This would be pretty hard, as we’d have to examine generated assembly or run debugger through each case. Supporting that in the future could cause
problems as well. Maintenance costs are likely to be far bigger than performance gains.

If you find that this change is beneficial in your project, you shouldn’t have any trouble implementing it. Engine-wise the optimization probably would be too aggressive.



I understand indeed, thanks for the quick answer!