开发者

How [MethodImpl(MethodImplOptions.NoInlining)] method attribute in C# , can affect performance when working with arrays?

开发者 https://www.devze.com 2023-02-01 11:06 出处:网络
How [MethodImpl(MethodImplOptions.NoInlining)] method attribute in C#, can affect performance when working with arrays?

How [MethodImpl(MethodImplOptions.NoInlining)] method attribute in C#, can affect performance when working with arrays?

I have a method, which iterates over int[][] - jagged array. With or without this attribute, performance measurement gave the same effect .

Should inlining give some improveme开发者_如何学运维nt when working with jagged arrays?


Iterating a two-dimensional array would normally be expensive enough to hide the cost of the single method call. And makes it likely that the method doesn't get inlined anyway, even without the attribute, just because there's too much machine code.

But have a look-see. Tools + Options, Debugging, General, untick "Suppress JIT optimization on module load". Select the Release build. Set a breakpoint on the method call and run. When it breaks, right-click the source code and click Go To Disassembly. If you see a call instruction then it didn't get inlined. You might see some machine code before the call if the method takes arguments.


It's likely that your method is not inlined whether you have the attribute or not - the JIT has some restrictions (not all methods can be inlined - i.e. ones having struct arguments), and some heuristics (most methods are not inlined - there are several heuristics based on control flow usage, bytecode instruction count, etc.).

This is a useful summary of the rules: http://blogs.msdn.com/b/davidnotario/archive/2004/11/01/250398.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消