Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking Method Inlining in C#

Tags:

c#

inline

Is there any way I can check (not force) if a given method or property getter is being inlined in a release build?

like image 268
Miguel Avatar asked Mar 21 '11 19:03

Miguel


People also ask

What is function inlining in C?

An inline function is one for which the compiler copies the code from the function definition directly into the code of the calling function rather than creating a separate set of instructions in memory. This eliminates call-linkage overhead and can expose significant optimization opportunities.

What is method inlining?

2. What Method Inlining Is? Basically, inlining is a way to optimize compiled source code at runtime by replacing the invocations of the most often executed methods with its bodies. Although there's compilation involved, it's not performed by the traditional javac compiler, but by the JVM itself.

How do you check if a function has been inlined?

The most reliable way to see if a function is being inlined or not is to look at the output from the compiler. Most compilers have a switch to output assembler code for your inspection.

What is inlining a variable?

A variable declared inline has the same semantics as a function declared inline: it can be defined, identically, in multiple translation units, must be defined in every translation unit in which it is used, and the behavior of the program is as if there was exactly one variable.


1 Answers

I know this post is rather old, but you just could print out the stack where you call the function and in the function you call itself.

If the printed out stack matches you can be sure, that the function was inlined.

To print out the stack you can use System.Environment.StackTrace or VS Varibles $caller and $callstack (https://msdn.microsoft.com/en-us/library/5557y8b4.aspx#BKMK_Print_to_the_Output_window_with_tracepoints)

like image 58
S. John Fagone Avatar answered Sep 22 '22 15:09

S. John Fagone