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

Introduction to Swift Performance - Try! Swift 2016

Introduction to Swift Performance - Try! Swift 2016

Danielle Tomlinson

September 01, 2016
Tweet

More Decks by Danielle Tomlinson

Other Decks in Programming

Transcript

  1. p: Index* Stack class Index { let section: Int let

    item: Int } let i = Index(section: 1, item: 1) Heap section: Int item: Int
  2. i: Index* Stack class Index { let section: Int let

    item: Int } let i = Index(section: 1, item: 1) let i2 = i Heap section: Int item: Int i2: Index*
  3. i: Index* Stack class Index { let section: Int let

    item: Int } let i = Index(section: 1, item: 1) __swift_retain(i) let i2 = i Heap section: Int item: Int i2: Index*
  4. section: 1 item: 1 Stack struct Index { let section:

    Int let item: Int } let i = Index(section: 1, item: 1)
  5. Stack struct Index { let section: Int let item: Int

    } let i = Index(section: 1, item: 1) let i2 = i section: 1 item: 1 section: 1 item: 1
  6. name: StringA* id: StringB* Stack struct User { let name:

    String let id: String } let u = User(name: "Joe", id: "1234")
  7. name: StringA* id: StringB* Stack name: StringA* id: StringB* struct

    User { let name: String let id: String } let u = User(name: "Joe", id: "1234") __swift_retain(u.name._textStorage) __swift_retain(u.id._textStorage) let u2 = u
  8. Example (0.3s) : struct Circle { let radius: Double let

    center: Point func draw() {} } var circles = (1..<100_000_000).map { _ in Circle(...) } for circle in circles { circle.draw() }
  9. Example (4s) : protocol Drawable { func draw() } struct

    Circle: Drawable { let radius: Double let center: Point func draw() {} } let drawables: [Drawable] = (1..<100_000_000).map { _ in Circle(...) } for drawable in drawables { drawable.draw() }
  10. struct Circle { let radius: Double let center: Point func

    draw() {} } var circles = (1..<100_000_000).map { _ in Circle(...) } for circle in circles { circle.draw() }
  11. protocol Drawable { func draw() } struct Circle: Drawable {

    let radius: Double let center: Point func draw() {} } var drawables: [Drawable] = (1..<100_000_000).map { _ in return Circle(...) } for drawable in drawables { drawable.draw() }
  12. protocol Drawable { func draw() } struct Circle: Drawable {

    let radius: Double let center: Point func draw() {} } var drawables: [Drawable] = (1..<100_000_000).map { _ in return Circle(...) } for drawable in drawables { drawable.draw() } draw() CircleDrawable ...
  13. Example (45s) : protocol Drawable { func draw() } struct

    Line: Drawable { let origin: Point let end: Point func draw() {} } let drawables: [Drawable] = (1..<100_000_000).map { _ in Line(...) } for drawable in drawables { drawable.draw() }
  14. In Practice Stack origin Line vwt pwt end LineDrawable copy:

    ... Heap drawable: func draw(drawable: Drawable) { drawable.draw() } let value: Drawable = Line() draw(local: value) // Generates func draw(value: ECTDrawable) { var drawable: ECTDrawable = ECTDrawable() let vwt = value.vwt let pwt = value.pwt drawable.vwt = value.vwt drawable.pwt = value.pwt vwt.allocateBuffAndCopyValue(&drawable, value) pwt.draw(vwt.projectBuffer(&drawable) }