Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The classic candidate for inlining is an accessor, like <code>std::vector&lt;T&gt;::size()</code>. </p> <p>With inlining enabled this is just the fetching of a variable from memory, likely <strong><em>a single instruction</em></strong> on any architectures. The "few pushes and a jump" (plus the return) is easily <strong><em>multiple times</em></strong> as much. </p> <p>Add to that the fact that, the more code is visible at once to an optimizer, the better it can do its work. With lots of inlining, it sees lots of code at once. That means that it might be able to <strong><em>keep the value in a CPU register</em></strong>, and completely spare the costly trip to memory. Now we might take about a difference of <strong><em>several orders of magnitude</em></strong>. </p> <p>And then theres <strong><em>template meta-programming</em></strong>. Sometimes this results in calling many small functions recursively, just to fetch a single value at the end of the recursion. (Think of fetching the value of the first entry of a specific type in a tuple with dozens of objects.) With inlining enabled, the optimizer can directly access that value (which, remember, might be in a register), <strong><em>collapsing dozens of function calls</em></strong> into accessing a single value in a CPU register. This can turn a terrible performance hog into a nice and speedy program. </p> <hr> <p>Hiding state as private data in objects (encapsulation) has its costs. Inlining was part of C++ from the very beginning in order to <strong><em>minimize these costs of abstraction</em></strong>. Back then, compilers were significantly worse in detecting good candidates for inlining (and rejecting bad ones) than they are today, so manually inlining resulted in considerable speed gainings.<br> Nowadays compilers are reputed to be much more clever than we are about inline. Compilers are able to inline functions automatically or don't inline functions users marked as <code>inline</code>, even though they could. Some say that inlining should be left to the compiler completely and we shouldn't even bother marking functions as <code>inline</code>. However, I have yet to see a comprehensive study showing whether manually doing so is still worth it or not. So for the time being, I'll keep doing it myself, and let the compiler override that if it thinks it can do better. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload