What kind of optimizations do both the C# compiler and the JIT do?

ⅰ亾dé卋堺 提交于 2019-11-30 06:45:23

I can imagine there being a number of optimizations that are unique to JIT; specifically, any optimization that depends on the environment/context that the application runs in. (Note, all the following are hypothetical, I do not know for sure, which or if any of these are actually performed)

Most boring: the JIT can optimize depending on 32-bit/64-bit underlying OS, or even potentially depending on the exact processor architecture.

Not applicable: More interesting: the JIT could optimize out anything that only runs in Debug mode (certain conditional code for example) when the application is not run inside a debug context.

Most interesting: the JIT could optimize out conditional branches in a class that depend only on a readonly field, because at least theoretically that value will never change during the execution of the class.

Basically I'd imagine that deferring optimizations until JIT would generally be the way to go, because at JIT time there is the most information available about the context the code is actually running in, making more meaningful optimizations possible.

peterchen

David Notario has a few posts on his blog (you can start here, and then walk the history), but they are rather sketchy.

I don't think the C# compiler does any optimizations. The JIT does all the work.

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