Regarding C++11 noexcept

The Visual C++ issue about the possibly negative performance effect of noexcept is still active, actually! It’s even relevant for the latest version of VS2019! There’s another aspect that I was not aware of before. It appears that MSVC does not inline-expand a noexcept member function of a DLL-imported class! Even if it would do so for a non-noexcept member function! As reported by gast128, April 16, 2020 in the discussion at https://developercommunity.visualstudio.com/content/problem/425370/c11-noexcept-implementation-still-a-performance-lo.html

I think it’s also interesting to read the comments Terry Mahaffey [MSFT]. Basically there’s another question, independent of noexcept: Should the compiler ever inline-expand a member function of a DLL-imported class, at all? What do you think?

1 Like

If you want to guarantee that you can apply a (security) update in a library by only updating the DLL in the application, then never inline would be needed. However, requiring to rebuild a whole applicate for updates may be OK for some high performance applications. The view form Terry Mahaffey seems to be coming from a systems application perspective as opposed to a scientific computing perspective.

1 Like

Thanks, Bradley @blowekamp It sounds to me like an extra compiler option would be useful, to specify either “inline-expand whenever possible”, or “dll-import whenever possible”. (I only tried MSVC optimization option /O2 so far.)

Here a simple code example: Compiler Explorer
As follows:

class __declspec(dllimport) MyClass
{
public:
    void f() {}
    void g() noexcept {}
};

int main()
{
    MyClass var;
    var.f(); // Function call inline-expanded by MSVC
    var.g(); // Function call via DLL-import
}

A new book on C++, “Embracing Modern C++ Safely”, by John Lakos, Vittorio Romeo, Rostislav Khlebnikov, and Alisdair Meredith (https://emcpps.com) has an extensive section dedicated to noexcept.

I made it into the Acknowledgments section of the book :blush:

Niels Dekker reviewed another unsafe C++11 feature (see Section 3.1.“noexcept Specifier” on page 1085) and provided valuable additional information as well as pointers to his own benchmark research.

My noexcept benchmark is still online: GitHub - N-Dekker/noexcept_benchmark: Compares the performance effect of 'noexcept' to an implicit exception specification

4 Likes