← Back to the chapter · Previous detail
Technical detail · Software Optimization Techniques
Function inlining and image growth
Inlining makes a different trade. A normal call may require argument setup, a branch-and-link, prologue/epilogue work, return, and inhibited optimization across the call boundary. Replacing the call site with the function body removes that boundary and can expose constants to further optimization. If a three-instruction helper is called in a hot inner loop, this can be valuable. If a 200-byte body is inserted at 40 sites, it creates roughly 8 kB before secondary transformations and may damage cache or update-slot fit.
Not every function is inlineable: recursion, indirect calls, separately linked code, debug or instrumentation requirements, and toolchain limits can prevent it. In C and C++, inline also has language linkage semantics and is generally a request, not a command. Toolchain-specific always-inline attributes may force a stronger attempt, but they still need a build-size and correctness review.
Use this stepwise decision:
- Measure call frequency and the cycles attributable to the call boundary.
- Inspect optimized assembly to confirm a call actually remains.
- Inline only the small, hot candidate and rebuild.
- Compare hot-path cycles, total flash, instruction-cache behavior, and whole-cycle charge.
- Retain the change only if the saved active energy exceeds the extra fetch and storage cost with update margin intact.
Predication and inlining both trade control-flow overhead for more instructions in the straight-line path. Their success is therefore visible in disassembly and a current trace, not in the source keyword alone.