iOS & swift

xcode ๋นŒ๋“œ ์‹œ๊ฐ„ ์ค„์ด๊ธฐ

ggasoon2 2023. 9. 6. 10:29

 

 

 

 

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