PSA: Compiler optimisation remarks

Oh! I'm Sorry! I assumed it was something being used internally or for optimiser development. But it is super-helpful, so thank you very much for creating it!

Yeah in one day it has already helped me discover that:

  • withContiguousStorageIfAvailable fallbacks for String.UTF8View were resulting in more specializations than I expected. It's really subtle and easy to miss, but I managed to reduce my binary size by 20% (!) by avoiding that.

  • Some of my algorithms should be split in to small functions for better inlining

  • Some theoretical fast paths in my algorithms were incurring ARC. I've seen big benefits by slimming them down.

  • wCSIA is not eliminated until late in the optimiser pipeline, so the compiler specialises my program 3 or 4 times more than it needs to, then discards most of what it did. I filed SR-15624 about it. No impact on size or performance, but there are potentially compile-time savings there.

That spelling doesn't seem to work on 5.5.2/Xcode 13.2, but I added it and to the post as the preferred spelling.

The feedback I can give is that it's great :smiley:, but if you have a function which is specialised multiple times, the results can look a bit cluttered and it's hard to tell them apart. For example, this function is inlined in some specializations but not in others, and it's not clear which:

Also, it's not clear why some specializations are generated. I was looking everywhere for what was causing the String.UTF8View specializations to be generated (bear in mind that it may not even be reachable code, as in SR-15624).

6 Likes