Run Time Inlining in C#?

帅比萌擦擦* 提交于 2019-12-07 23:29:28

问题


A couple of questions on C#

  1. Does C# support runtime inlining?
  2. Does JIT's optimizate before or during the execution of the code?
  3. Can a virtual function be inlined?

回答1:


C# the language doesn't do inlining, but the .NET CLR JIT compiler can.

Virtuals might be inline-able in a sealed class, but I'm not sure about non-sealed classes. I would assume not.

JIT optimizes before the execution of the code, when a function is first called. Because before the JIT goes to work, you don't have any code to execute. :P JIT happens only once on the first call to a function, not on every call to the function.

Note also that inlining is only done within an assembly (DLL). The JIT compiler will not copy code from another assembly to inline it into the code of this assembly.




回答2:


C# doesn't support any inlining explicitly. JIT compiler may do some inlining behind the stage while optimizing.




回答3:


The C# compiler itself does not do inlining (which you can verify by opening the assembly in Reflector). The CLR's JIT compiler does inlining, here is one blog post on the subject (many more are out there).

Note that in general, .NET compilers cannot do inlining across DLL boundaries since a DLL can change after code that depends on the DLL has been compiled. So it makes sense to do inlining at run-time.



来源:https://stackoverflow.com/questions/2784982/run-time-inlining-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!