String, improving compilation time

Optimizing Build Times in Swift is a frequently discussed issue. I found a great article on this topic. @Tyler.milner paid attention to the long time of compilation for String interpolation and I decided to extend this part of story. In my previous article I’ve showed execution time of String interpolation. Now I will focus on build time.
But how to check how much time the compilation took? You can easily download and run a special tool BuildTimeAnalyzer (however, interference in the project settings will be required) or run script (that avoids this problem)
I’ve used the same model that I used earlier
This is the result

Adding interpolated strings is the least efficient. It is almost 70 times more than the fastest than String format. You can think “it’s only 19ms”, yes only 19ms, but still 70 times more than the fastest solution, and this is only one line of code. What if there were more than one? Let’s check it! I’ve copied each line 60 times.

The compiler has guessed how to handle third function, but now different between the fastest and the slowest is over 280ms. I have to admit that now it’s not 70 times, but only 24 times slower.
Conclusions
Don’t underestimate the compilation time. You can gain a lot at a low cost. In some cases, you can increase performance by up to several dozen percent by changing only a few lines of code.
Thank you for reading! If you liked this article, please clap so other people can read it too. I will also have more motivation for next article :) You can also see my other articles, maybe you will find something for you.
If you have any question or suggestion leave a comment.
