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

Swift Performance

Kishikawa Katsumi
February 20, 2016
1.7k

Swift Performance

Swift Optimization Tips

Kishikawa Katsumi

February 20, 2016
Tweet

Transcript

  1. ܭଌ͢Δ func measure(call: () -> Void) { let startTime =

    CACurrentMediaTime() call() let endTime = CACurrentMediaTime() print("Time - \(endTime - startTime)") }
  2. ܭଌ͢Δ func measure(call: () -> Void) { let startTime =

    CACurrentMediaTime() call() let endTime = CACurrentMediaTime() print("Time - \(endTime - startTime)") } measure { // Heavy task }
  3. ίʔυͷੑೳΛ্͛Δʹ͸ ˖ &YQMJDJU  ״׶⸬桦ך葺ְ،ٕ؞ٔؤيח㢌ִ׷  ٍؗحءُ׾㼪Ⰵׅ׷  ؝٦سך㢌刿չ㣐պ 

    〳铣䚍הךزٖ٦سؔؿ ˖ *NQMJDJU  鎉铂ך剑黝⻉׾ⵃ欽ׅ׷  ؝٦سך㢌刿չ㼭պ  鎉铂暴剣
  4. ࠷దԽΛ֬ೝ͢Δʹ͸ $ xcrun swiftc --help OVERVIEW: Swift compiler USAGE: swiftc

    [options] <inputs> MODES: -dump-ast Parse and type-check input file(s) and dump AST(s) -dump-parse Parse input file(s) and dump AST(s) -dump-type-refinement-contexts Type-check input file(s) and dump type refinement contexts(s) -emit-assembly Emit assembly file(s) (-S) -emit-bc Emit LLVM BC file(s) -emit-executable Emit a linked executable -emit-ir Emit LLVM IR file(s) ...
  5. ࠷దԽΛ֬ೝ͢Δʹ͸ ˖ FNJUBTTFNCMZ&NJUBTTFNCMZMF T  4  ˖ FNJUJS&NJU--7.*3MF T

     ˖ FNJUTJCHFO&NJUTFSJBMJ[FE"45 SBX4*-MF T  ˖ FNJUTJM&NJUDBOPOJDBM4*-MF T
  6. Reference TypeΑΓValueTypeΛ࢖͏ struct NumberValue { let x: Int } class

    NumberReference { let x: Int init(x: Int) { self.x = x } }
  7. LazyCollection let numbers = Array(1...1000) let lazyNumbers = numbers.lazy let

    doubledNumbers = lazyNumbers.map { $0 * 2 } doubledNumbers.last let lazyNumbers2 = LazyCollection(numbers) let doubledNumbers2 = lazyNumbers.map { $0 * 2 } doubledNumbers2.last