WWDC 3

Understanding Swift Performance - 3

이번에는 Generic을 활용한 Performance적인 부분을 한번 살펴보도록 하겠습니다. // Drawing a copy protocol Drawable { func draw() } func drawACopy(local : Drawable) { local.draw() } Drawable이라는 프로토콜 타입을 파라미터로 받는 drawACopy 메서드가 있습니다. 우리가 이것을 사용할때에는 아래의 코드와 같이 사용할 수 있습니다. // Drawing a copy protocol Drawable { func draw() } func drawACopy(local : Drawable) { local.draw() } let line = Line() drawACopy(line) //... let point = P..

WWDC 2021.03.07

Understanding Swift Performance - 2

이번에는 Protocol Type과 Generic Code의 Performance에 대한 부분입니다. Protocol 이번에는 Protocol 타입을 활용한 코드로 살펴보겠습니다. protocol Drawable { func draw() } struct Point: Drawable { var x, y: Double func draw() { ... } } struct Line: Drawable { var x1, y1, x2, y2: Double func draw() { ... } } var drawables: [Drawable] for d in drawables { d.draw() } Drawable 클래스 추상화를 대신하여 이번에는 Protocol Drawable을 사용한 모습을 볼 수 있습니다. 그리고..

WWDC 2021.03.07

Understanding Swift Performance - 1

WWDC2016의 세션 중 하나인 Understanding Swift Performance에 대한 공부를 해보았습니다. Understanding Siwft Performance 올바른 추상화 메커니즘을 선택하는 것은 코드를 만드는 과정, Performance적인 부분에서 많은 영향을 줍니다. Struct를 사용하여 모델링을 할 것인지? Class를 사용하여 모델링을 할 것인지? 정말 자주하는 고민입니다! 추상화를 설계하고, 추상화 mechanism을 선택할 때 어떤 부분을 고려할 수 있을까? 내 instance가 Stack에 할당하는게 좋을까? 아니면 Heap에 할당하는게 좋을까? (Allocation) 이 instance를 전달할 때 얼마나 많은 Reference Counting 오버헤드를 발생시킬까?..

WWDC 2021.03.04