Skip to main content

Swift optimize compiling time

Compiling development have pain in the ass issues: compiling time. With many mainly Script developer like me, we familiar with edit => refresh => testing => done. But with compiling language like iOS Swift or Android Java/Kotlin, even single bit of change to source code require rebuild (In my knowledge). And it make newbie more stress, panic since you are new and have to make small change step by step to trial and error to see what take effect...
I mean newbie have to make more build

Time compiling >=2 minutes (120s)
 Slowest ~5 minutes

- ~500 file source => 50-75s compile
- assets ~500files ~7s
- XIB some take huge time to compile (15-23s); randomly slow each build ie. TagUser..xib some time slow, so it hard to know exactly which xib slow.
- The more file, module included, the more tangled, required messing, So it hard to comment out/ exclude one file. And then total compile time spike up.

1. Almost all Pods libraries already removed:
- Twitter
- Facebook
- Line
- Fabric
- Deploygate ...
And other package like Adobe Creative SDK ...

2. Only GoogleMap, KingFisher and some light (?) package left.
Assets have about 600+ files (already cleaned by Fengniao) but it seem it only take 7s to compile.

3. Excluded about 100-200 file in Utility, some less used module

4. Debug flag
OPTIMIZE_COMPILATION_ALL enabled

5. Ignore signing app
...

All above setup is designed for Debug (Develop) target.

After all optimization, it seem build/compile time still slow. normally it may take 25 to 30s but quite often it spike to 50-60s.

So ~500-700 source files is a thing. In addition 160 xib, storyboard take huge time to build/compile.

Exclude 5 slowest xib not take much effect.


So it seem the culprit lie here: huge number of source files and xib/storyboard.

The only way to reduce compile time seem exclude these file (for only feature/module that u currently work on). Certainly, these file, feature often tangled and required between each other, so we have to modified some script, config.

Some tip on Edit:

Vim is a powerful tool. Both .xcodeproj/project.pbxproj, Source file like Info.plist, Appdelegate ... or event xib/storyboard (with careful). So we have less defend on XCode IDE slow edit.
For example, u can edit Project.xcodeproj/project.pbxproj directly instead of using XCode > Settings > Exclude menu ...
And You can remove file and update xcodeproj/project.pbxproj file later instead of use delete menu on IDE.
And surely, Git is a must have tool to track, store history of change.

   The real deal by using vim is that, in many case we can not simple exclude folder because of often we have to required some files inside it. So the only way / simple way is ignore many single file. And using editor instead of GUI XCode is much more efficient.


Log debugging here:
https://stackoverflow.com/questions/40489663/where-xcode-8-places-build-logs
~/Library/Developer/Xcode/DerivedData/... your_project_name-hash

Aha -bash: /usr/bin/du: Argument list too long
May be iTerm2 is a piece of shit.

$du -sh * |grep -v "K\t"    # list folder size exclude K sized one. May be need | sort -n


Diving Into Xcode Logs


WebRefs:
https://github.com/fastred/Optimizing-Swift-Build-Times/blob/master/README.md
http://joemburgess.com/2014/10/04/diving-into-xcode-logs/
https://github.com/spotify/XCLogParser
https://www.freecodecamp.org/news/learn-linux-vim-basic-features-19134461ab85/
https://stackoverflow.com/questions/13861658/is-it-possible-to-search-though-all-xcodes-logs
 

Update 1: 17/12/2019

I found that XCode have export function for analysis log.

And then we can use bash tool like vim, grep for extract information needed.
For example, I want to find all Compiled Swift files in order to know what files have excluded successfully.
$ grep "CompileSwift" xcode-log-17_Dec_19.txt > xcode-swift-log.txt
Remove "CompileSwiftSource" that out of above filter.
You can use reverse grep (grep -v) or vim delete line contain:
:g/keyword/d

Finally, we should sort  log-file.txt for easier view.



Comments

Popular posts from this blog

Rand mm 10

https://stackoverflow.com/questions/2447791/define-vs-const Oh const vs define, many time I got unexpected interview question. As this one, I do not know much or try to study this. My work flow, and I believe of many programmer is that search topic only when we have task or job to tackle. We ignore many 'basic', 'fundamental' documents, RTFM is boring. So I think it is a trade off between the two way of study language. And I think there are a bridge or balanced way to extract both advantage of two method. There are some huge issue with programmer like me that prevent we master some technique that take only little time if doing properly. For example, some Red Hat certificate program, lesson, course that I have learned during Collage gave our exceptional useful when it cover almost all topic while working with Linux. I remember it called something like RHEL (RedHat Enterprise Linux) Certificate... I think there are many tons of documents, guide n books about Linux bu

Martin Fowler - Software Architecture - Making Architecture matter

  https://martinfowler.com/architecture/ One can appreciate the point of this presentation when one's sense of code smell is trained, functional and utilized. Those controlling the budget as well as developer leads should understand the design stamina hypothesis, so that the appropriate focus and priority is given to internal quality - otherwise pay a high price soon. Andrew Farrell 8 months ago I love that he was able to give an important lesson on the “How?” of software architecture at the very end: delegate decisions to those with the time to focus on them. Very nice and straight-forward talk about the value of software architecture For me, architecture is the distribution of complexity in a system. And also, how subsystems communicate with each other. A battle between craftmanship and the economics and economics always win... https://hackernoon.com/applying-clean-architecture-on-web-application-with-modular-pattern-7b11f1b89011 1. Independent of Frameworks 2. Testable 3. Indepe