Method Inlining

An optimization performed by some compilers, whereby a method call is replaced by the actual code of the method being called.


Described: http://developer.java.sun.com/developer/technicalArticles/Networking/HotSpot/index.html

Example in the JavaLanguage: http://developer.java.sun.com/developer/technicalArticles/Networking/HotSpot/inlining.html


(moved from WellFactoredCodeLeadsToBetterOptimizations)

InlineMethod is certainly the most obvious optimizations for WellFactoredCode, and can yield amazing results, particularly if your target hardware has a tiny I-cache (stand up, Mr PlayStation 2). Once you've made it past this fairly obvious milestone, is WellFactoredCode going to be any easier to optimize?

Inlining is also not controllable in C++. The compiler may or may not inline your code. Some later change can turn off the inlining and nobody will know what happened. In these cases, you need to unfactor your code.

Using gcc, extracting a method tends to lose you the optimizations that can be done across the method boundaries due to all kinds of reasons. However, if you mark the function "static" (file scope) suddenly gcc can optimize it as if it was inlined - even if it was called from multiple places within this file. gcc often inlines the entire function, or at the very least bypasses the usual stack handling that's required. I personally think that compilers should be able to InlineMethods on their own during optimization.


In C++ (CeePlusPlus) The inline specifier is a hint to the compiler that inline substitution of the function body is to be preferred to the usual function call implementation. The hint may be ignored. ... A function declared within the declaration of a class is inline by default.


CategoryOptimization


EditText of this page (last edited November 10, 2005) or FindPage with title or text search