In the Swift project I finished recently there was a very strange behavior. At some point I noticed that autocomplete totally stopped working and the indexer was constantly spinning. Only if I would wait for what felt like minutes, things would settled down and it was working fine for a while. Only to re-appear again after I add few more types or methods.
It’s rather large project with about 60k lines of code, but still was really strange. After I got fed up, I began hunting for solution. Luckily for me, rather quickly I found Soroush’s post describing these unofficial Other Swift Flags:
This warns you when any of your methods take over 100ms to finish type-checking. In my project, I found few nasty surprises:
This last method, taking up 27s to type-check, had a total of 5 lines and the problem turned out to be string concatenation. When I replaced it with string interpolation, it dropped below 50ms.
This was really insane and I was curious why would this one line cause so much work for Swift compiler. Matt Gallagher of Cocoa with Love encountered this few months before me, found the issue and even offered a solution.
update: Jordan Rose chimed in on Twitter about the proposed solution: