Inlining – The Ultimate Optimisation
xania.org
xania.org
I believe it was counting AST nodes rather than bytes, otherwise that would have also created problems for descriptive function names as well and that would have been what we heard about instead of comments.
The function was something like:
int ReturnAnswerIfCharIsValid(char* c)
{
if(c == nullptr)
throw std::exception("ERROR!");
return 42;
}
The exception line was changed to something like: throw std::exception("Char is not valid, please fix it!"); // String is now longer
The performance of this hot-path function went down the drain.I fixed it by replacing the exception call with yet another function call:
if(c == nullptr)
ThrowException();
Other fixes might have included something like __forceinline in the function signature.So you're really banking on this not affecting your program. Which it doesn't, if you keep it in mind and do it sparingly. But if you start making everything virtual it should hit you vs. merely making everything noinline.
https://hubicka.blogspot.com/2014/02/devirtualization-in-c-p...
Ad hoc polymorphism (C++ templates) and parametric polymorphism (Rust) can be inlined. Although those examples are slow to compile, because they must be specialized for each set of generic arguments.
Even if the compiler doesn’t explicitly do it, it can happen when doing subsequent optimization steps after inlining such as constant folding and dead code elimination.
https://gcc.gnu.org/onlinedocs/gccint/IPA-passes.html https://gcc.gnu.org/onlinedocs/gccint/Regular-IPA-passes.htm... https://gcc.gnu.org/onlinedocs/gccint/Late-IPA-passes.html
If you have f(x, y) and the compiler realizes the function optimizes nicely when y == 2 it can create a clone of f with a fixed argument y == 2, optimize that, and rewrite the appropriate call sites to call the clone.
EDIT: i'm le dumb - this is the whole point of JIT compilers.
Inlining the upper character: (char c, bool upper) as 0xff subtraction.
There's also flatten; unfortunately no equivalent with MSVC.