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

App startup time with Dynamic/Static frameworks

App startup time with Dynamic/Static frameworks

Shota Kashihara

March 19, 2019
Tweet

More Decks by Shota Kashihara

Other Decks in Technology

Transcript

  1. ©2019 Wantedly, Inc. App startup time with Dynamic/Static frameworks try!

    Swift Pre Talk 2019 Mar 19, 2019 - @ShotaKashihara
  2. ©2019 Wantedly, Inc. Xcode ͱ Frameworks ͷྺ࢙ Xcode 5 #2013೥

    ɹɾOnly Static Library (Obj-C) Dynamic/Static Framework Λ ͓͞Β͍
  3. ©2019 Wantedly, Inc. Xcode ͱ Frameworks ͷྺ࢙ Xcode 5 #2013೥

    ɹɾOnly Static Library (Obj-C) Xcode 6 #2014೥ ɹɾSupport embedded frameworks (Dynamic Library) Dynamic/Static Framework Λ ͓͞Β͍
  4. ©2019 Wantedly, Inc. Xcode ͱ Frameworks ͷྺ࢙ Xcode 5 #2013೥

    ɹɾOnly Static Library (Obj-C) Xcode 6 #2014೥ ɹɾSupport embedded frameworks (Dynamic Library) Xcode 9 #2017೥ ɹɾSupport static library with Swift ɹɹɾCocoa Pods (v1.5.0), Carthage (v0.30.1) ʹͯ ରԠࡁ Dynamic/Static Framework Λ ͓͞Β͍
  5. ©2019 Wantedly, Inc. Framework ֦ுࢠ .framework ɾϥΠϒϥϦ ɾ(όϯυϧ) ɹɾNib ɹɾը૾

    ɹɾϔομʔϑΝΠϧ ͳͲΛ·ͱΊͨϑΥϧμ Dynamic/Static Framework
  6. ©2019 Wantedly, Inc. Dynamic Framework .framework ɾಈతϥΠϒϥϦ (.dylib, or ֦ுࢠͳ͠)

    ɹΛؚΜͩ Framework ɾArchive ɹɾ<YourApp>/Frameworks/ ഑Լʹ ɹɹ.framework ͷ··ίϐʔ Dynamic/Static Framework
  7. ©2019 Wantedly, Inc. Static Framework .framework ɹ ɾArchive ɹɾ੩తϥΠϒϥϦ͸ίϯύΠϧ࣌ʹ੩తϦϯΧʹΑͬͯɺ ɹɹ࣮ߦՄೳϑΝΠϧʹؚ·ΕΔ(୯ҰͷϑΝΠϧʹͳΔ)

    ɹɾϦιʔεϑΝΠϧ͸ΞϓϦέʔγϣϯ഑Լʹίϐʔͯ͠ɺ ɹɹ࣮ߦՄೳϑΝΠϧ͔Βݟ͑Δঢ়ଶʹ͢Δඞཁ͋Γ Dynamic/Static Framework ← Static Library ͸ίϯύΠϧͰ ࣮ߦՄೳϑΝΠϧͷҰ෦ʹͳΔ ɾ੩తϥΠϒϥϦ (.a, or ֦ுࢠͳ͠) ɹΛؚΜͩ Framework
  8. ©2019 Wantedly, Inc. exec() to main() ΞϓϦ্ཱ͕͕ͪΔ·ͰʹཪଆͰى͖͍ͯΔ͜ͱ ※ WWDC 2016

    (Optimizing App Startup Time) ʹͯݴٴ͞ΕͨςʔϚ exec() to main()
  9. ©2019 Wantedly, Inc. exec() 1. Kernel maps your application into

    new address space 2. Kernel loads helper program 3. Dyld runs in-process exec() to main()
  10. ©2019 Wantedly, Inc. exec() 1. Kernel maps your application into

    new address space 2. Kernel loads helper program 3. Dyld runs in-process exec() to main()
  11. ©2019 Wantedly, Inc. exec() 1. Kernel maps your application into

    new address space 2. Kernel loads helper program 3. Dyld runs in-process exec() to main()
  12. ©2019 Wantedly, Inc. exec() 1. Kernel maps your application into

    new address space 2. Kernel loads helper program 3. Dyld runs in-process exec() to main()
  13. ©2019 Wantedly, Inc. exec() 1. Kernel maps your application into

    new address space 2. Kernel loads helper program 3. Dyld runs in-process Dyld: ࣮ߦ࣌ʹ dynamic library ΛಡΈࠐΉϓϩηεͷ͜ͱ exec() to main()
  14. ©2019 Wantedly, Inc. Dyld Steps 1. Map all dependent dylibs,

    recurse 2. Rebase all images 3. Bind all images 4. ObjC prepare images 5. Run initializers exec() to main()
  15. ©2019 Wantedly, Inc. Dyld Steps 1. Map all dependent dylibs,

    recurse 2. Rebase all images 3. Bind all images 4. ObjC prepare images 5. Run initializers exec() to main()
  16. ©2019 Wantedly, Inc. Dyld Steps 1. Map all dependent dylibs,

    recurse 2. Rebase all images 3. Bind all images 4. ObjC prepare images 5. Run initializers exec() to main()
  17. ©2019 Wantedly, Inc. Dyld Steps 1. Map all dependent dylibs,

    recurse 2. Rebase all images 3. Bind all images 4. ObjC prepare images 5. Run initializers exec() to main() ͜ΕΒ͕ Dynamic Framework ͷ਺͚ͩ࠶ؼ͢Δ
  18. ©2019 Wantedly, Inc. exec() to main() ɾΞϓϦͷىಈ࣌ʹ Dyld ͕࠶ؼతʹ Framework

    ΛϝϞϦʹ഑ஔ͢Δ ɾDynamic Framework ͷ਺͚ͩΦʔόʔϔου͕૿͑Δ ɹ exec() to main()
  19. ©2019 Wantedly, Inc. exec() to main() ɾΞϓϦͷىಈ࣌ʹ Dyld ͕࠶ؼతʹ Framework

    ΛϝϞϦʹ഑ஔ͢Δ ɾDynamic Framework ͷ਺͚ͩΦʔόʔϔου͕૿͑Δ ɹ ɹˠ ෳ਺ͷ Dynamic Frameworks Λ Static Library ͱͯ͠Ϗϧυͯ͠ɺ ɹɹ ͦΕΒΛ·ͱΊͨ Dynamic Frameworks Λ࡞Δ exec() to main()
  20. ©2019 Wantedly, Inc. ΞϓϦ ͷߏ੒ Domain.framework Main.app Watch.app Umbrella frameworks

    C.framework B.framework (3rd party) A.framework Static linking
  21. ©2019 Wantedly, Inc. Summary ɾDynamic frameworks ͕૿͑Δͱ Dyld ͷίετ͕͔͔Δ ɾΞϓϦͷىಈ଎౓͕ؾʹͳͬͨΒ

    DYLD_PRINT_STATISTICS ΦϓγϣϯͰ ɹDynamic Library ͷϩʔυʹ͔͔͍ͬͯΔ࣌ؒΛݟͯΈΑ͏ ɾDynamic frameworks Λ Static Frameworks ʹஔ͖׵͑ͯ ɹDyld ͷίετΛݮΒ͢͜ͱ΋બ୒ࢶͷҰͭ App startup time with Dynamic/Static frameworks