AggressiveInlining.` The JIT compiler logically determines which methods to inline. But sometimes we know better than it does. With AggressiveInlining, we give the compiler a hint. We tell it that the method should be inlined. `Attribute `attribute`Example.` This example benchmarks a method with no attribute, and with AggressiveInlining. The method body contains several lines of useless code. This makes the method large in bytes, so the JIT compiler may decide not to inline it. `We apply the MethodImplOptions.AggressiveInlining option to Method2. This is an enum.`We see that` with no options, the method calls required seven nanoseconds each. But with inlining specified (with AggressiveInlining), the calls required less than one nanosecond each. `Consider for a moment all the things you could do with those seven nanoseconds.`Tip 2: `If you are scheduling your life based on nanoseconds, please consider reducing your coffee intake.`Discussion.` This is a micro-optimization. For critical algorithms, using a micro-optimization on hot code is often worthwhile. But this is the uncommon case. Most code needs little optimization.`When to use AggressiveInlining.` To which methods should we apply this option? I have found that larger methods, such as the one in the example, benefit from this sort of inlining. `If a method is called only once in an enclosing method, it may help to inline it even if it is large.`However: `If a large method is called in many places in a program, inlining it will reduce locality of reference and may ruin performance.`Locality of Reference `locality-of-reference`Summary.` Method calls have a cost, but also a benefit. They cause an activation record to be added to the evaluation stack. But they also reduce instruction count. Our challenge is to find the best balance between these considerations.

56889:DQ!DQbJAiy%9gggiyby,`wiyg3y,`wiyg3'0#O'0#O5u?ig9K^}^}^^}^}^^}^}^^gg?ig9K^}^}^^}^}^^}^}^^g 66; 666.Runtime.CompilerServices666 { 5const 6_max610000000; 565{8 556Compile the m6s. 558M61(); 55M62(); 556sum60655var s166.6New(); 556(6i60; i < _max; i++) 55{ 555sum += M61(); 55} 55s16; 55var s266.6New(); 556(6i60; i < _max; i++) 55{ 555sum += M62(); 55} 55s26; 556(6(s1.6 * 1000000) / 555_max).To6("0.00 ns")); 556(6(s2.6 * 1000000) / 555_max).To6("0.00 ns")); 556.6(); 5} 566M61() 5{8 556No inlining suggestion. 5586 "one".L66"two".L66"three".L6 + 555"four".L66"five".L66"six".L6 + 555"seven".L66"eight".L66"nine".L6 + 555"ten".L6; 5} 5[M6Impl(8M6ImplOptions.AggressiveInlining8)] 566M62() 5{8 556Aggressive inlining. 5586 "one".L66"two".L66"three".L6 + 555"four".L66"five".L66"six".L6 + 555"seven".L66"eight".L66"nine".L6 + 555"ten".L6; 5} } 8Results8 87.34 ns85No options 80.32 ns85M6ImplOptions.AggressiveInlining8