Micro blogpost : Compiler is your best friend

Sumeet More
1 min readAug 12, 2023

--

Disclaimer: This article is based on my current knowledge and understanding. If you have any query or see any improvement, please mention in the comment section

We all have written code with if else statement. Sometimes, in assembly code, it will translate to jump instruction. CPU always tries to predict which all instructions will execute next. However, with if else code/jump instruction, it gets tricky for CPU to predict which can sometimes cause performance penalty if mispredicted. you might ask Sumit for a simple if else? yes performance penalty does occur if the same piece of code is executed a million times. However, there is another interesting assembly instruction CMOV which the compiler can produce for if else statement and eliminate the cost of misprediction .

From image, we can see .NET 7 produces jump instruction for if else statement however, .NET 8 optimises if else statement with CMOV instruction

--

--

Sumeet More
Sumeet More

Written by Sumeet More

Software Engineer 2 at Microsoft | Backend Engineer and Architect| Blockchain & ML enthusiast | C#,.NET Core, Rust, Javascript and Go

No responses yet