Hacker News new | ask | show | jobs
by munificent 1151 days ago
The problem with not inlining is less with the overhead of the function call itself, and more the loss of further optimization opportunities. Consider this (trivial) example:

    main() {
      int x = foo() + 3;
    }

    int foo() {
      return 5;
    }
Without inlining you have both the overhead of the call and the arithmetic addition. If you can inline the call then you get:

    main() {
      int x = 5 + 3;
    }
But more importantly, the optimizer can now also eliminate the addition too:

    main() {
      int x = 8;
    }
This is obviously a trivial example, but in real-world code, the optimization options opened up after inlining are important.