Messagepack-csharp: Squeeze Performance out of loops

Created on 26 Apr 2019  路  4Comments  路  Source: neuecc/MessagePack-CSharp

Basically, switch foreach loop to for

wontfix

Most helpful comment

When in doubt, you can look at the IL between a foreach and a for loop. I think for an array the compiled IL is identical.
Another layer (and ultimately the one that matters) that you can check is release build disassembly.

All 4 comments

This does not always make perf better, and in fact can make iteration worse on some collection types. When used over an array, there is no difference.

On Unity (the old runtime) the foreach loop used to be slower because of the old runtime, which still tried to box the access by using IEnumerator...

With the new runtime it should behave way better and optimized

This does not always make perf better, and in fact can make iteration worse on some collection types. When used over an array, there is no difference.

Thanks for the insightful feedback BenchmarkDotNet is a liar 馃槀

When in doubt, you can look at the IL between a foreach and a for loop. I think for an array the compiled IL is identical.
Another layer (and ultimately the one that matters) that you can check is release build disassembly.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

neuecc picture neuecc  路  6Comments

Lf3T-Hn4D picture Lf3T-Hn4D  路  8Comments

MetaCitizenOffical picture MetaCitizenOffical  路  3Comments

AArnott picture AArnott  路  3Comments

SylphiaWindy picture SylphiaWindy  路  3Comments