Optimising struct equality checks – NextMove Software
Summary
Whilst working on an upcoming feature for our Arthor search system (the topic of another future blogpost! Looking through the flame chart for this new feature showed mostly what I was expecting, as well as an unexpected visitor, the equality operator ( ) for our AtomType struct. For the sake of argument, it looks roughly like this: The method is nothing fancy, just going through each field in the struct and checking that their values are equal. Better yet, this function call gets inlined and the assembly produced by all compilers now shows that this operation is being done in far fewer instructions and without any branching! This has split the 11 bytes into much more computer friendly (i.e. addressable) chunks of 8, 2 and 1, required 3 total loads and comparisons.