The new iOS application that I’m working on – written 100% in Swift – was noticeably taking much longer to compile than should, given its size (~200 files). More concerning, it was suddenly a lot slower than only a couple of weeks prior. I needed to get to the root of the problem as soon as possible, before it got any worse.
Identify methods with slow compilation time and take action!
Add -Xfrontend -debug-time-function-bodies to my Swift compiler flags
Using the xcodebuild command line tool results in the logs being printed to standard output, where we can message them to our liking:
xcodebuild -workspace App.xcworkspace -scheme App clean build | grep [1-9].[0-9]ms | sort -nr > culprits.txt
You may also want to sort the result by the amount of times methods gets compiled:
Best list compilation was to sort by the multiplication the time a method needs to get compiled with the numbers a method gets compiled.
I actually had 1,200+ cases in which a function took more than a second, with many taking over three seconds. Rewriting just these three lines of code caused my entire project to build 60% faster.
irace
Identify methods with slow compilation time and take action!
Add -Xfrontend -debug-time-function-bodies to my Swift compiler flags
Using the xcodebuild command line tool results in the logs being printed to standard output, where we can message them to our liking:
xcodebuild -workspace App.xcworkspace -scheme App clean build | grep [1-9].[0-9]ms | sort -nr > culprits.txt
You may also want to sort the result by the amount of times methods gets compiled:
awk -F '\t' '{print $2}' < culprits.txt | sort | uniq -c | sort -nr > culprits_count.txt
Best list compilation was to sort by the multiplication the time a method needs to get compiled with the numbers a method gets compiled.
I actually had 1,200+ cases in which a function took more than a second, with many taking over three seconds. Rewriting just these three lines of code caused my entire project to build 60% faster.
irace
Comments
Post a Comment