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

AWS Elasticache Memcached connection

https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/accessing-elasticache.html#access-from-outside-aws http://hourlyapps.blogspot.com/2010/06/examples-of-memcached-commands.html Access memcached https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/GettingStarted.AuthorizeAccess.html Zip include hidden file https://stackoverflow.com/questions/12493206/zip-including-hidden-files phpmemcachedadmin ~ phpMyAdmin or phpPgAdmin ... telnet mycachecluster.eaogs8.0001.usw2.cache.amazonaws.com 11211 stats items stats cachedump 27 100 https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/VPCs.EC.html https://lzone.de/cheat-sheet/memcached VPC ID Security Group ID (sg-...) Cluster: The identifier for the cluster memcached1 Creation Time: The time (UTC) when the cluster was created January 9, 2019 at 11:47:16 AM UTC+7 Configuration Endpoint: The configuration endpoint of the cluster memcached1.ahgofe.cfg.usw1.cache.amazonaws.com:11211 St...

Notes Windows 10 Virtualbox config, PHP Storm Japanese, custom PHP, Apache build, Postgresql

 cmd => Ctrl + Shift + Enter mklink "C:\Users\HauNT\Videos\host3" "C:\Windows\System32\drivers\etc\hosts" https://www.quora.com/How-to-create-a-router-in-php https://serverfault.com/questions/225155/virtualbox-how-to-set-up-networking-so-both-host-and-guest-can-access-internet 1 NAT + 1 host only config https://unix.stackexchange.com/questions/115464/how-to-properly-set-up-2-network-interfaces-in-centos-running-in-virtualbox DEVICE=eth0 TYPE=Ethernet #BOOTPROTO=dhcp BOOTPROTO=none #IPADDR=10.9.11.246 #PREFIX=24 #GATEWAY=10.9.11.1 #IPV4_FAILURE_FATAL=yes #HWADDR=08:00:27:CC:AC:AC ONBOOT=yes NAME="System eth0" [root@localhost www]# cat /etc/sysconfig/network-scripts/ifcfg-eth1 # Advanced Micro Devices, Inc. [AMD] 79c970 [PCnet32 LANCE] DEVICE=eth1 IPADDR=192.168.56.28 <= no eff => auto like DHCP #GATEWAY=192.168.56.1 #BOOTPROTO=dhcp BOOTPROTO=static <= no eff ONBOOT=yes HWADDR=08:00:27:b4:20:10 [root@localhost www]# ...

Rocket.Chat DB schema

_raix_push_notifications avatars.chunks avatars.files instances meteor_accounts_loginServiceConfiguration meteor_oauth_pendingCredentials meteor_oauth_pendingRequestTokens migrations rocketchat__trash rocketchat_cron_history rocketchat_custom_emoji rocketchat_custom_sounds rocketchat_import rocketchat_integration_history rocketchat_integrations rocketchat_livechat_custom_field rocketchat_livechat_department rocketchat_livechat_department_agents rocketchat_livechat_external_message rocketchat_livechat_inquiry rocketchat_livechat_office_hour rocketchat_livechat_page_visited rocketchat_livechat_trigger rocketchat_message rocketchat_oauth_apps rocketchat_oembed_cache rocketchat_permissions rocketchat_raw_imports rocketchat_reports rocketchat_roles rocketchat_room rocketchat_settings rocketchat_smarsh_history rocketchat_statistics rocketchat_subscription rocketchat_uploads system.indexes users usersSessions https://rocket.chat/docs/developer-guides/sc...