Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Build時間改善

Naoto Onagi
December 02, 2016

 Build時間改善

CA.swift [https://eventdots.jp/event/606151] で発表した内容になります
iOS開発において、Build時間を短くするための流れやTipsをまとめました

コードベースの改善については、以下にSample Projectを用意してあります
https://github.com/naoto0n2/BuildTimeSample/

【追記】
OTHER_SWIFT_FLAGS に -Xfrontend -debug-time-function-bodies を設定することで計測処理の分Build時間が遅くなります
計測が終わった後は外しておくことをおすすめします

Naoto Onagi

December 02, 2016
Tweet

Other Decks in Technology

Transcript

  1. ฒྻ$PNQJMF਺ ฒྻ$PNQJMF਺͝ͱͷ#VJME࣌ؒ ฒྻ$PNQJMF਺ #VJME࣌ؒ<T>      

        $PSF਺पลͷ஋Ͱ Ұ൪଎͍஋Λௐ΂͓ͯ͘ ˠ EFGBVMUTXSJUFDPNBQQMFEU9DPEF *%&#VJME0QFSBUJPO.BY/VNCFS0G$PODVSSFOU$PNQJMF5BTLT
  2. ࠷దԽ݁Ռ #VJME5JNF<T> 48*'5@8)0-&@.0%6-&@015*.*;"5*0/ /P :FT ࠩ෼#VJME   $MFBO#VJME 

     w ࠩ෼#VJME͕஗͘ͳΔ w $MFBO#VJME͕େ෯ʹ଎͘ͳΔ ˠ
  3. ࠷దԽ݁Ռ #VJME5JNF<T> 48*'5@8)0-&@.0%6-&@015*.*;"5*0/ /P :FT ࠩ෼#VJME   $MFBO#VJME 

     w ࠩ෼#VJME͕஗͘ͳΔ w $MFBO#VJME͕େ෯ʹ଎͘ͳΔ ˠ
  4. ܕਪ࿦ʹ͕͔͔࣌ؒΔύλʔϯ func lateMethod(type: SampleType, text: String?) -> String { switch

    type { case .type1: return "1: Hoge " + (self.generateText() ?? "nil") + " Fuga " + type.rawValue + " " + (text ?? "nil") case .type2: return "2: Hoge " + (self.generateText() ?? "nil") + " Fuga " + type.rawValue + " " + (text ?? "nil") case .type3: return "3: Hoge " + (self.generateText() ?? "nil") + " Fuga " + type.rawValue + " " + (text ?? "nil") case .type4: return "4: Hoge " + (self.generateText() ?? "nil") + " Fuga " + type.rawValue + " " + (text ?? "nil") case .type5: return "5: Hoge " + (self.generateText() ?? "nil") + " Fuga " + type.rawValue + " " + (text ?? "nil") } } enum SampleType: String { case type1 = "type1" case type2 = "type2" case type3 = "type3" case type4 = "type4" case type5 = "type5" } private func generateText() -> String? { return (arc4random() % 2 == 0) ? "text" : nil }
  5. ܕਪ࿦ʹ͕͔͔࣌ؒΔύλʔϯ func lateMethod(type: SampleType, text: String?) -> String { switch

    type { case .type1: return "1: Hoge " + (self.generateText() ?? "nil") + " Fuga " + type.rawValue + " " + (text ?? "nil") case .type2: return "2: Hoge " + (self.generateText() ?? "nil") + " Fuga " + type.rawValue + " " + (text ?? "nil") case .type3: return "3: Hoge " + (self.generateText() ?? "nil") + " Fuga " + type.rawValue + " " + (text ?? "nil") case .type4: return "4: Hoge " + (self.generateText() ?? "nil") + " Fuga " + type.rawValue + " " + (text ?? "nil") case .type5: return "5: Hoge " + (self.generateText() ?? "nil") + " Fuga " + type.rawValue + " " + (text ?? "nil") } } enum SampleType: String { case type1 = "type1" case type2 = "type2" case type3 = "type3" case type4 = "type4" case type5 = "type5" } private func generateText() -> String? { return (arc4random() % 2 == 0) ? "text" : nil } ˣ NT
  6.  ԋࢉࢠʹΑΔ݁߹Λ΍ΊΔ ܕਪ࿦ʹ͕͔͔࣌ؒΔύλʔϯ func fastMethod1(type: SampleType, text: String?) -> String

    { switch type { case .type1: return "1: Hoge \(self.generateText() ?? "nil") Fuga \(type.rawValue) \(text ?? "nil")" … } }
  7.  ԋࢉࢠʹΑΔ݁߹Λ΍ΊΔ ܕਪ࿦ʹ͕͔͔࣌ؒΔύλʔϯ func fastMethod1(type: SampleType, text: String?) -> String

    { switch type { case .type1: return "1: Hoge \(self.generateText() ?? "nil") Fuga \(type.rawValue) \(text ?? "nil")" … } } NTˠNT
  8.  ॲཧΛࣄલʹߦ͏ ܕਪ࿦ʹ͕͔͔࣌ؒΔύλʔϯ func fastMethod2(type: SampleType, text: String?) -> String

    { let text = text ?? "nil" switch type { case .type1: let generatedText = self.generateText() ?? "nil" return "1: Hoge " + generatedText + " Fuga " + type.rawValue + " " + text … } }
  9.  ॲཧΛࣄલʹߦ͏ ܕਪ࿦ʹ͕͔͔࣌ؒΔύλʔϯ NTˠNT func fastMethod2(type: SampleType, text: String?) ->

    String { let text = text ?? "nil" switch type { case .type1: let generatedText = self.generateText() ?? "nil" return "1: Hoge " + generatedText + " Fuga " + type.rawValue + " " + text … } }
  10. ܕਪ࿦ʹ͕͔͔࣌ؒΔύλʔϯ func lateMethod(data: Data) { self.log(data: [ "userId": data.user?.id ??

    "userId", "userName:": data.user?.name ?? "userName", "errorCodeString": "\(data.errorCode)", "description": data.description ?? "Description" ]) } struct Data { let user: User? let errorCode: Int let description: String? } struct User { let id: String? let name: String? } private func log(data: [String: Any]) { // Send log data to server } NT
  11. ܕਪ࿦ʹ͕͔͔࣌ؒΔύλʔϯ NT ಛ௃  Ҿ਺Λ౉࣌͢௚઀%JDUJPOBSZΛੜ੒  Λ%JDUJPOBSZͷWBMVFࢦఆ࣌ʹ࢖༻ func lateMethod(data: Data)

    { self.log(data: [ "userId": data.user?.id ?? "userId", "userName:": data.user?.name ?? "userName", "errorCodeString": "\(data.errorCode)", "description": data.description ?? "Description" ]) } struct Data { let user: User? let errorCode: Int let description: String? } struct User { let id: String? let name: String? } private func log(data: [String: Any]) { // Send log data to server }
  12. ܕਪ࿦ʹ͕͔͔࣌ؒΔύλʔϯ func fastMethod(data: Data) { let userId = data.user?.id ??

    "userId" let userName = data.user?.name ?? "userName" let errorCodeString = "\(data.errorCode)" let description = data.description ?? "Description" let data = [ "userId": userId, "userName:": userName, "errorCodeString": errorCodeString, "description": description ] self.log(data: data) } ˠ NT NT func lateMethod(data: Data) { self.log(data: [ "userId": data.user?.id ?? "userId", "userName:": data.user?.name ?? "userName", "errorCodeString": "\(data.errorCode)", "description": data.description ?? "Description" ]) } struct Data { let user: User? let errorCode: Int let description: String? } struct User { let id: String? let name: String? } private func log(data: [String: Any]) { // Send log data to server }
  13. ܕਪ࿦ʹ͕͔͔࣌ؒΔύλʔϯ func lateMethod(size: CGSize) -> CGSize { return CGSize( width:

    size.width + (view1?.bounds.width ?? 0) + (view2?.bounds.width ?? 0) + 10, height: size.height) } var view1: UIView? var view2: UIView? NT
  14. ܕਪ࿦ʹ͕͔͔࣌ؒΔύλʔϯ func lateMethod(size: CGSize) -> CGSize { return CGSize( width:

    size.width + (view1?.bounds.width ?? 0) + (view2?.bounds.width ?? 0) + 10, height: size.height) } var view1: UIView? var view2: UIView? NT ಛ௃  $(4J[FJOJUJBMJ[FSͷҾ਺ʹ௚઀ෳࡶͳࣜ  $('MPBUͱܕ͕ෆ໌ྎͳ਺஋ͷࠞࡏ
  15. ܕਪ࿦ʹ͕͔͔࣌ؒΔύλʔϯ func lateMethod(size: CGSize) -> CGSize { return CGSize( width:

    size.width + (view1?.bounds.width ?? 0) + (view2?.bounds.width ?? 0) + 10, height: size.height) } var view1: UIView? var view2: UIView? NT func fastMethod2(size: CGSize) -> CGSize { let view1Width: CGFloat = view1?.bounds.width ?? 0 let view2Width: CGFloat = view2?.bounds.width ?? 0 let newWidth: CGFloat = size.width + view1Width + view2Width + 10 return CGSize(width: newWidth, height: size.height) } ˠ NT
  16. size.width + (view1?.bounds.width ?? 0) + (view2?.bounds.width ?? 0) +

    10 ܕਪ࿦ʹ͕͔͔࣌ؒΔύλʔϯ $('MPBU $('MPBU
  17. size.width + (view1?.bounds.width ?? 0) + (view2?.bounds.width ?? 0) +

    10 ܕਪ࿦ʹ͕͔͔࣌ؒΔύλʔϯ size.width + (view1?.bounds.width ?? 0) + (view2?.bounds.width ?? 0) + 10 $('MPBU $('MPBU $('MPBU $('MPBU $('MPBU ˣ
  18. ܕਪ࿦ʹ͕͔͔࣌ؒΔύλʔϯ size.width + (view1?.bounds.width ?? 0) + (view2?.bounds.width ?? 0)

    + 10 $('MPBU $('MPBU size.width + (view1?.bounds.width ?? 0) + (view2?.bounds.width ?? 0) + 10 $('MPBU public func +(lhs: CGFloat, rhs: CGFloat) -> CGFloat ˣ
  19. ܕਪ࿦ʹ͕͔͔࣌ؒΔύλʔϯ size.width + (view1?.bounds.width ?? 0) + (view2?.bounds.width ?? 0)

    + 10 public func +(lhs: CGFloat, rhs: CGFloat) -> CGFloat size.width + (view1?.bounds.width ?? 0) + (view2?.bounds.width ?? 0) + 10 $('MPBU ˣ
  20. ܕਪ࿦ʹ͕͔͔࣌ؒΔύλʔϯ size.width + (view1?.bounds.width ?? 0) + (view2?.bounds.width ?? 0)

    + 10 $('MPBU size.width + (view1?.bounds.width ?? 0) + (view2?.bounds.width ?? 0) + 10 public func +(lhs: CGFloat, rhs: CGFloat) -> CGFloat ˣ
  21. ܕਪ࿦ʹ͕͔͔࣌ؒΔύλʔϯ size.width + (view1?.bounds.width ?? 0) + (view2?.bounds.width ?? 0)

    + 10 public func +(lhs: CGFloat, rhs: CGFloat) -> CGFloat size.width + (view1?.bounds.width ?? 0) + (view2?.bounds.width ?? 0) + 10 $('MPBU ˣ
  22. ܕਪ࿦ʹ͕͔͔࣌ؒΔύλʔϯ let newWidth: CGFloat = size.width + view1Width + view2Width

    + 10 ˣ let newWidth: CGFloat = size.width + view1Width + view2Width + 10 $('MPBU $('MPBU $('MPBU $('MPBU $('MPBU
  23. w $PNQJMFS͕͙͢ਪ࿦Ͱ͖ΔΑ͏ܕ৘ใΛ༩͑Δ w ಛʹ Λ࢖͏ͱ͖͸ద੾ʹܕΛࢦఆ w ߦͰԋࢉࢠʹΑΔ݁߹Λ͗͢͠ͳ͍ w ܕਪ࿦͕଎͍ˠγϯλοΫεϋΠϥΠτ΋଎͍ w

    'VODUJPOBM1SPHSBNNJOHͰى͖͕ͪͳγϯλοΫεϋΠϥΠτ͕
 ஗͍ݱ৅Λճආ͢Δ͜ͱ΋ w ͨͩ͠ʮਪ࿦͠΍͢͞ʯͱʮ4XJGUZͳίʔυʯ͸
 τϨʔυΦϑͳ͜ͱ͕ଟ͍ w ݦஶʹ஗͍ՕॴͷΈͷվળͰे෼ ܕਪ࿦ʹ͕͔͔࣌ؒΔύλʔϯ·ͱΊ