Understanding Swift Performance

Groot·2022년 10월 10일
0

TIL

목록 보기
83/148
post-thumbnail

TIL

🌱 난 오늘 무엇을 공부했을까?

📌 Understanding Swift Performance

📍 Dimensions of Performance

  • Allocation
    • heap, stack
  • Reference Counting
  • Method Dispatch
    • V-Table
      • 호출하는 메서드를 관리하는 테이블

🔗 Static Dispatch

  • compile-time
  • Value Type(Struct, Enum)

🔗 Dynamic Dispatch

  • runtime
  • Reference Type(Class)
  • Protocol(Witness Table)

📍 Protocol Type

  • class의 다형성을 대체
  • 큰 값의 struct도 참조형태로 사용될 수도 있다
  • class보단 성능이 좋다.

📍 Generic Code

  • 다형성을 대체하지만, Static Dispatch를 사용
  • Specialization이 된 Generic의 경우만 성능이 개선

📍 Summary

🔗 Choose fitting abstraction with the least dynamic runtime type requirements

  • struct types: value semantics
  • class types: identity or OOP style polymorphism
  • Generics: Static polymorphism
  • Porotocol types: dynamic polymorphism
profile
I Am Groot

0개의 댓글