xcode ๋น๋ ์๊ฐ ์ค์ด๊ธฐ
1. Build With Timing Summary
๋น๋ ์๊ฐ์ ์์ฝํ๊ณ ์ต์ ํ ํด์ค๋ค๊ณ ํจ.

2. Xcode Build Setting ์์ ( TARGETS -> Build Setting ์์ ๊ฒ์ํ๋ฉด ๋์ด )
a) BUILD ACTIVE ARCHITECTURE ONLY
Debug: Yes
Release: No
b) COMPILATION MODE
Debug: Incremental
Release: Whole Module
c) OPTIMIZATION LEVEL
Debug: No Optimization [-Onone]
Release: Optimize for Speed [-O]
d) DEBUG INFORMATION FORMAT (DWARF)
Debug: DWARF
Release: DWARF with DSYM File
3. code siginig ์์
a) ์ํธํ ๊ธฐ๋ฒ SHA-1 ๋์ ๋น ๋ฅธ SHA-256 ์ผ๋ก ์ฌ์ฉ (๋๋ฒ๊ทธ ๋ชจ๋์์)
b) ๋น resourceRules.plist ์์ฑํ์ฌ ์ฒ์ ํด์ํด์ผํ๋ ์์ ์๊ฐ ์ค์
resourceRules.plist ์ ์ฝ๋
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>rules</key>
<dict>
<key>.*</key>
<false/>
</dict>
</dict>
</plist>
4. Pod ์ข ์์ฑ ์์
Podfile ๋งจ ์๋์ ์ฝ๋ ์ถ๊ฐ
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
if config.name.include?("Debug") then
config.build_settings['ONLY_ACTIVE_ARCH'] = 'YES'
config.build_settings['OTHER_SWIFT_FLAGS'] = ['$(inherited)', '-Onone']
config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = '-O'
config.build_settings['SWIFT_COMPILATION_MODE'] = 'singlefile'
end
end
end
end
5. init ํ์ ๋ช ์
์ ์ด๋ฏธ์ง๋ฅผ ๋ณด๋ฉด UIColor๋ฅผ init์ผ๋ก ํ์๋๋ฐ ์ด๋ฌ๋ฉด ์๊ฐ์ด ๊ต์ฅํ ์์๋จ
initํ ๋ initํ๋ ํ์ ์ ๋ช ์ํด์ฃผ๋ฉด ์๊ฐ์ ์์ฃผ ์ ์ฝํ ์ ์์
-> .init ๋์ UIColor.init ์ฌ์ฉ
6. ์๊ฐ ์ค์ด๋ code ์์ฑ
a) ๋ณ์ ์ ์ธ์ ๊ฐ๋ฅํ let ์ฌ์ฉ
b) ์์์ด ํ์ ์๋ ํด๋์ค์ ๊ฒฝ์ฐ final ๋ถ์ด๊ธฐ
c) ์ธ๋ถ์ ์ ๊ทผ์ด ์๋ ๊ฒฝ์ฐ private ์ฌ์ฉํ๊ธฐ
d) ํ์ค ๋ณด๋ค๋ ์ฌ๋ฌ์ค๋ก ๋๋ ์ ์์ฑํ๊ธฐ
// Before:
let finalValue = CGFloat(collectionView.contentSize.height - (((self.viewModel as? CartViewModelV2)?.cancellationCellHeight ?? 0) + 44))
// After:
let collectionViewHeight: CGFloat = collectionView.contentSize.height
let cancellationCellHeight: CGFloat = (self.viewModel as? CartViewModelV2)?.cancellationCellHeight ?? 0
let finalValue = CGFloat(collectionViewHeight - (cancellationCellHeight + 44))
e) optional ๊ฐ์ ๋ํ์ฌ ?? ๋ณด๋ค๋ if let ์ฌ์ฉ
๊ทธ ์ธ ์๊ฐ ๊ด๋ จ ์ค์
7. ํฐ๋ฏธ๋์ ์ด ์ฝ๋๋ฅผ ์ณ์ ๋น๋ ์๊ฐ์ ์ธก์ ํ ์ ์๋ค.
defaults write com.apple.dt.Xcode ShowBuildOperationDuration YES
๊ทธ๋ฌ๋ฉด ์ด๋ ๊ฒ ์๊ฐ์ด ๋ธ

8. ์๊ฐ์ด ์ค๋๊ฑธ๋ฆฌ๋ (e.g. 100ms์ด์) code line ์ warning์ ๋์ธ ์ ์๋ค.
๋น๋์ ํ Other Swift Flags ์ ์๋ ์ฝ๋๋ฅผ ์ถ๊ฐํด์ค๋๋ค
-Xfrontend -warn-long-function-bodies=100
-Xfrontend -warn-long-expression-type-checking=100
์ด๋ฐ์์ผ๋ก ์๊ฐ์ด ๋ธ (11826ms)
์ ๋ฐฉ๋ฒ์ผ๋ก
3 ~ 10๋ถ ๊ฑธ๋ฆฌ๋ ๋น๋๊ฐ
1๋ถ ~ 3๋ถ๊น์ง ์ค์ด๋ค์๋ค์.
๋๋ฌด ์ ์ฉํ์ฌ ์ ๋ฆฌํ์์ต๋๋ค
์ถ์ฒ: https://bytes.swiggy.com/build-time-optimizations-xcode-911c9c3ac8ff