Inlining¶
Function inlining is an important concept for performance optimization. However, standard C++ provides only a single inline specifier, which doesn’t have its behavior defined precisely. We address this by exposing related compiler extensions in a portable way.
Reference¶
#include <actl/functional/inlining/AC_ALWAYS_INLINE.hpp>
-
AC_ALWAYS_INLINE¶
Macro to force inlining of a function to avoid an explicit function call.
Typically used for simple functions after observing that the compiler doesn’t inline them as expected. For example,
AC_ALWAYS_INLINE int squared(int x) { return x * x; }
Note
Should be used with caution to avoid undesirable binary size increase and potential performance loss because of higher instruction cache utilization.
Note
It’s not recommended to overuse it because it disables stepping into the function in debug mode on some platforms.
#include <actl/functional/inlining/AC_NEVER_INLINE.hpp>
-
AC_NEVER_INLINE¶
Macro to prevent inlining of a function, typically to reduce binary size. For example,
template<typename Exception, typename... Args> [[noreturn]] AC_NEVER_INLINE void throw_exception(Args&&... args) { throw Exception{std::forward<Args>(args)...}; }
Note
Should be used with caution because of the potential overhead of the added function call.
See tests at tests/functional/inlining.cpp
Design¶
Compiler extension for AC_NEVER_INLINE is typically called noinline.
Aiming for improved clarity, we chose a different name
which is symmetric to AC_ALWAYS_INLINE.