BY Simmi Kava7 Jun 2021 Edit
C# - Aggressive Inlining

Aggressive Inlining - When it doesn't work ?


What is Inlining?

A process in which code is copied from one function directly in to the body of the another function (i.e. to the function which uses the code from the called function).

What are it's advantages?

  • Stack is reduced i.e. variables need not be push and pop from the stack.
  • Context specific optimization on the body of function is feasible.
  • No function call or return call overhead needs to be maintained.

What is Aggressive Inlining?

JIT (Just In Time) compiler can logically determine which methods can be inlined. But at times, we know logic better than the compiler. Isn't it? So how do we force JIT compiler to perform the inlining? The answer is "Aggressive Inlining",

Syntax:

[MethodImpl(MethodImplOptions.AggressiveInlining)]

static int MethodName() { }

Name the scenarios, where Aggressive Inlining won't work?

  • MarshalByRef : Since calls have to intercepted, executed and dispatched, MarshalByRef classes cannot be inlined.

  • Virtual Calls : Since the end target of the call is unknown, this is ignored.

  • Valuetypes : When valuetypes are passed as reference or when valuetypes are copied by compiler to avoid unexpected mutation.

  • Virtual Machine(VM) Restrictions : JIT needs to seek permission from the VM to inline a method e.g. like in iOS this is just not possible as platform doesn't allow it.

  • Complex Flowgraph : This includes complex loops or exception handling (try-catch) and similar scenarios.

Besides this, any security probe or non-native IL instructions are also out of scope of inlining.

Hope you learnt something new today. Happy Monday!

    -
BY Simmi Kava
LikeCommentSave
LikeCommentSaveShare
0
Categories
General
YantraJS
Developer Guides
Tutorials
Web Atoms Updates

POPULAR POSTS
17 Mar 2021
LATEST ACTIVITY
Simmi Kava
commented this post.
Simmi Kava
liked this post.
Show more
ARCHIVES
2025
2024
2023
2022
TAGS
javascript (56)
developer (25)
javascriptdeveloper (16)
Xamarin.Forms (16)
Html (14)
typescript (12)
webatoms (12)
xamarin (11)
coding (10)
web-atoms (10)
arrays (9)
android (8)
javascript-developer (8)
csharp (7)
dotnet (7)
css (6)
update (6)
dotnet-standard (5)
function (5)
iOS (5)
methods (4)




Web Atoms: JSX (TSX + TypeScript) for Xamarin.Forms, Hot Reload Your App in Production Environment

PlaygroundSamples Repository