LevelUp

dotnet JIT can eliminate branches provided that the flag in the condition is known as compile-time and it's not going to change over time.

It can be a field, property, of function which resolves to a const.

In this example, FlagA won't be eliminated since it generates a backing field. But there's a catch here since it will work when we convert it to a static expression property. The only problem is that it has to have its static initializer executed in Tier0 compilation and then it will get eliminated in Tier1 so it's a bit tricky to get right.

More JIT tricks and now well know facts here:

https://youtu.be/XLcPTf0efPk

https://youtu.be/soDX_IeZsqM

There's also an entire playlist on JIT alone:

www.youtube.com/playlist?list...

#csharp #dotnet #programming #performance

4 years ago | [YT] | 13