Bibi's DevLog ๐Ÿค“๐ŸŽ

About the App Launch Sequence ์•ฑ ์‹คํ–‰ ์‹œํ€€์Šค์— ๋Œ€ํ•˜์—ฌ ๋ณธ๋ฌธ

๐Ÿ“ฑ๐ŸŽ iOS/๐Ÿ Apple Developer Documentation

About the App Launch Sequence ์•ฑ ์‹คํ–‰ ์‹œํ€€์Šค์— ๋Œ€ํ•˜์—ฌ

๋น„๋น„ bibi 2022. 8. 27. 00:53

Learn the order in which the system executes your code at app launch time.

Apple Developer Documentation

์•ฑ ์‹คํ–‰ ์‹œํ€€์Šค์— ๋Œ€ํ•˜์—ฌ

์•ฑ์˜ ์‹คํ–‰ ์‹œ์ ์— ์‹œ์Šคํ…œ์ด ๋‹น์‹ ์˜ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜๋Š” ์ˆœ์„œ์— ๋Œ€ํ•ด ๋ฐฐ์›๋‹ˆ๋‹ค.

๊ฐœ์š”

์•ฑ์˜ ์‹คํ–‰์€ ๋ณต์žกํ•œ ๋‹จ๊ณ„์˜ ์ˆœ์„œ(์‹œํ€€์Šค)๋ฅผ ํฌํ•จํ•˜๋ฉฐ, ๊ทธ ๋Œ€๋ถ€๋ถ„์€ ์‹œ์Šคํ…œ์ด ์ž๋™์ ์œผ๋กœ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค. ์‹คํ–‰ ์‹œํ€€์Šค ์ค‘์—๋Š”, UIKit์€ ์•ฑ์˜ app delegate์˜ ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ๋‹น์‹ ์ด ์‚ฌ์šฉ์ž ์ƒํ˜ธ์ž‘์šฉ์„ ์ค€๋น„ํ•˜๊ณ , ์•ฑ์ด ์š”๊ตฌํ•˜๋Š” ํŠน์ • ์ž‘์—…๋“ค์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜์˜ ๊ทธ๋ฆผ์€ ์•ฑ์ด ์‹คํ–‰๋  ๋•Œ ๋ถ€ํ„ฐ ์‹œํ€€์Šค๊ฐ€ ์™„๋ฃŒ๋  ๋•Œ ๊นŒ์ง€, ์‹คํ–‰ ์‹œํ€€์Šค์˜ ๊ฐœ๋ณ„์ ์ธ ๋‹จ๊ณ„๋ฅผ ์„ค๋ช…ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค:

Untitled

  1. ์‚ฌ์šฉ์ž ๋˜๋Š” ์‹œ์Šคํ…œ์ด ๋‹น์‹ ์˜ ์•ฑ์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. ๋˜๋Š” ์‹œ์Šคํ…œ์ด ๋‹น์‹ ์˜ ์•ฑ์„ ์˜ˆ์—ด(prewarm)ํ•ฉ๋‹ˆ๋‹ค. prewarming์— ๋Œ€ํ•œ ๋” ๋งŽ์€ ์ •๋ณด๋ฅผ ์œ„ํ•ด์„œ๋Š” Prepare Your App for Prewarming ์„ ์ฐธ๊ณ ํ•˜์‹ญ์‹œ์˜ค.
  2. ์‹œ์Šคํ…œ์ด Xcode๊ฐ€ ์ œ๊ณตํ•˜๋Š” main() ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
  3. main() ํ•จ์ˆ˜๊ฐ€ UIApplication ๊ณผ ์•ฑ์˜ app delegate์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜๋Š” UIApplicationMain(_*:_*:_:_:)์„ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค. (= @main)
  4. UIKit์ด ์•ฑ์˜ Info.plist ํŒŒ์ผ ๋˜๋Š” Xcode ํ”„๋กœ์ ํŠธ ์—๋””ํ„ฐ target์˜ Custom iOS Target Propertiesํƒญ์— ๋‹น์‹ ์ด ์ง€์ •ํ•ด ๋‘” ๊ธฐ๋ณธ ์Šคํ† ๋ฆฌ๋ณด๋“œ(default storyboard)๋ฅผ ๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค; default storyboard๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ์•ฑ์€ ์ด ๋‹จ๊ณ„๋ฅผ ๊ฑด๋„ˆ๋œ๋‹ˆ๋‹ค.
  5. UIKit์ด ์•ฑ์˜ app delegate์— ์žˆ๋Š” application(_:willFinishLaunchingWithOptions:) ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค.
  6. UIKit์ด ์ƒํƒœ ๋ณต๊ตฌ๋ฅผ ์ˆ˜ํ–‰ํ•˜๋ฉฐ, ๊ทธ ๊ฒฐ๊ณผ๋กœ ์•ฑ์˜ app delegate์™€ view controller์— ์žˆ๋Š” ๋ฉ”์„œ๋“œ๋ฅผ ์ถ”๊ฐ€์ ์œผ๋กœ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. ๋” ๋งŽ์€ ์ •๋ณด๋ฅผ ์œ„ํ•ด์„œ๋Š” About the UI restoration process๋ฅผ ์ฐธ๊ณ ํ•˜์‹ญ์‹œ์˜ค.
  7. UIKit์ด ์•ฑ์˜ app delegate์— ์žˆ๋Š” application(_:didFinishLaunchingWithOptions:) ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค.

์‹คํ–‰ ์‹œํ€€์Šค๊ฐ€ ์™„๋ฃŒ๋˜๋ฉด, ์‹œ์Šคํ…œ์€ ๋‹น์‹ ์˜ app delegate ๋˜๋Š” scene delegate๋ฅผ ์‚ฌ์šฉํ•ด ์•ฑ์˜ UI(user interface)๋ฅผ ๋ณด์—ฌ์ฃผ๊ณ , UI์˜ ๋ผ์ดํ”„์‚ฌ์ดํด์„ ๊ด€๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

Prewarming(์˜ˆ์—ด)์„ ์œ„ํ•ด ์•ฑ์„ ์ค€๋น„ํ•˜๊ธฐ

iOS 15 ์ดํ›„, ์‹œ์Šคํ…œ์€ ๊ธฐ๊ธฐ์˜ ์ƒํ™ฉ์— ๋”ฐ๋ผ์„œ ๋‹น์‹ ์˜ ์•ฑ์„ prewarm(์˜ˆ์—ด) ํ•ฉ๋‹ˆ๋‹ค - ์‹คํ–‰ ์ค‘์ด์ง€ ์•Š์€ ์•ฑ์˜ ํ”„๋กœ์„ธ์Šค๋ฅผ ์‹œ์ž‘ํ•ด, ์‚ฌ์šฉ์ž๊ฐ€ ์•ฑ์ด ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•ด์งˆ ๋•Œ ๊นŒ์ง€ ๊ธฐ๋‹ค๋ ค์•ผ ํ•˜๋Š” ์‹œ๊ฐ„์„ ์ค„์ž…๋‹ˆ๋‹ค. Prewarming์€ ์•ฑ์˜ ์‹œ์ž‘ ์‹œํ€€์Šค์—์„œ main() ์ด UIApplicationMain(_:_:_:_:) ์„ ํ˜ธ์ถœํ•˜๊ธฐ ์ „๊นŒ์ง€์˜ ๊ณผ์ •์„ ์‹คํ–‰์‹œํ‚ต๋‹ˆ๋‹ค. ์ด๋Š” ์‹œ์Šคํ…œ์ด ์•ฑ์„ ์™„์ „ํžˆ ์‹œ์ž‘ํ•˜๋Š” ๊ฒƒ์— ํ•„์š”ํ•  ๊ฒƒ์œผ๋กœ ์˜ˆ์ธก๋˜๋Š” ์ €์ˆ˜์ค€์˜(low-level) ๊ตฌ์กฐ๋ฌผ๋“ค์„ ๋งŒ๋“ค๊ฑฐ๋‚˜ ์บ์‹ฑํ•  ๊ธฐํšŒ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

๋…ธํŠธ
์•ฑ์˜ ์‹œ์ž‘ ๋™์•ˆ ์‹œ์Šคํ…œ์ด ํ•„์š”๋กœ ํ•˜๋Š” ์ €์ˆ˜์ค€์˜ ๊ตฌ์กฐ๋ฌผ๋“ค์— ๋Œ€ํ•œ ๋” ๋งŽ์€ ์ •๋ณด์— ๋Œ€ํ•ด์„œ๋Š”, WWDC ์„ธ์…˜ ์˜์ƒ์ธ App Startup Time: Past, Present, and Future ๋ฅผ ์ฐธ์กฐํ•˜์‹ญ์‹œ์˜ค.

์‹œ์Šคํ…œ์ด ๋‹น์‹ ์˜ ์•ฑ์„ prewarmํ•˜๊ณ  ๋‚œ ๋‹ค์Œ์—๋Š”, ์•ฑ์ด ์‹œ์ž‘ํ•˜๊ณ  ์‹œํ€€์Šค๋ฅผ ๋‹ค์‹œ ์‹œ์ž‘ํ•  ๋•Œ ๊นŒ์ง€ ๊ทธ ์‹œ์ž‘ ์‹œํ€€์Šค๋ฅผ ๋ฉˆ์ถค(paused) ์ƒํƒœ๋กœ ๋‚จ๊ฒจ ๋‘˜ ์ˆ˜๋„ ์žˆ์œผ๋ฉฐ, ๋˜๋Š” ๋ฆฌ์†Œ์Šค๋ฅผ ๋‹ค์‹œ ๊ฐ€์ ธ์˜ค๊ธฐ ์œ„ํ•ด prewarm๋œ ์•ฑ์„ ๋ฉ”๋ชจ๋ฆฌ๋กœ๋ถ€ํ„ฐ ์ œ๊ฑฐํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ์‹œ์Šคํ…œ์€ ๊ธฐ๊ธฐ๊ฐ€ ์žฌ๋ถ€ํŒ…๋œ ์ดํ›„์—, ๊ทธ๋ฆฌ๊ณ  ์‹œ์Šคํ…œ์˜ ์ƒํ™ฉ์ด ํ—ˆ๋ฝํ•  ๋•Œ ์ฃผ๊ธฐ์ ์œผ๋กœ ๋‹น์‹ ์˜ ์•ฑ์„ prewarmํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋งŒ์•ฝ ๋‹น์‹ ์˜ ์•ฑ์ด UIApplicationMain(_:_:_:_:) ์˜ ํ˜ธ์ถœ ์ด์ „์— ์–ด๋–ค ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•œ๋‹ค๋ฉด (์˜ˆ๋ฅผ ๋“ค์–ด [load()](https://developer.apple.com/documentation/objectivec/nsobject/1418815-load) ์™€ ๊ฐ™์€ static ์ด๋‹ˆ์…œ๋ผ์ด์ €์ฒ˜๋Ÿผ), ์–ด๋–ค ์„œ๋น„์Šค๋‚˜ ์ž์›์ด ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ์ง€์— ๋Œ€ํ•œ ๊ฐ€์ •ํ•˜์ง€ ๋งˆ์‹ญ์‹œ์˜ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ํ‚ค์ฒด์ธ ์š”์†Œ๋Š” ์‚ฌ์šฉ์ด ๋ถˆ๊ฐ€๋Šฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์™œ๋ƒํ•˜๋ฉด ํ‚ค์ฒด์ธ์˜ ๋ฐ์ดํ„ฐ ๋ณดํ˜ธ ์›์น™์€ ์ž ๊ธˆ ํ•ด์ œ๋œ ๊ธฐ๊ธฐ๋ฅผ ์š”๊ตฌํ•˜๋Š”๋ฐ, prewarming์€ ๊ธฐ๊ธฐ๊ฐ€ ์ž ๊ธด ์ƒํƒœ์—์„œ๋„ ์ผ์–ด๋‚  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋งŒ์•ฝ ๋‹น์‹ ์˜ ์ฝ”๋“œ๊ฐ€ ํŠน์ •ํ•œ ์„œ๋น„์Šค ๋˜๋Š” ์ž์›์˜ ์ ‘๊ทผ์— ์˜์กดํ•˜๊ณ  ์žˆ๋‹ค๋ฉด, ๊ทธ ์ฝ”๋“œ๋ฅผ ์‹œ์ž‘ ์‹œํ€€์Šค ์ดํ›„์˜ ๋ถ€๋ถ„์œผ๋กœ ์˜ฎ๊ธฐ์‹ญ์‹œ์˜ค.

์•ฑ์„ prewarmํ•˜๋ฉด, prewarming ๋‹จ๊ณ„๊ฐ€ ์™„๋ฃŒ๋˜๋Š” ์‹œ์ ๊ณผ ์œ ์ €(๋˜๋Š” ์‹œ์Šคํ…œ)์ด ์•ฑ์„ ์™„์ „ํžˆ ์‹œ์ž‘ํ•˜๋Š” ์‹œ์  ์‚ฌ์ด์— ๋ถˆํ™•์‹คํ•œ ๊ธธ์ด์˜ ์‹œ๊ฐ„์ด ์ƒ๊น๋‹ˆ๋‹ค. ์ด ์‹œ๊ฐ„ ๋•Œ๋ฌธ์—, ์ˆ˜๋™์œผ๋กœ ์‹œ์ž‘ ์‹œํ€€์Šค์˜ ์—ฌ๋Ÿฌ ์‹œ์ ์— signpost(ํ‘œ์ง€๋ฅผ ๋‚จ๊ธฐ๋Š”)ํ•˜๊ธฐ๋ณด๋‹ค๋Š”, MetricKit์„ ์‚ฌ์šฉํ•ด ์‚ฌ์šฉ์ž๊ฐ€ ์ฃผ๋„ํ•˜๋Š” ์‹œ์ž‘ ๋ฐ ์žฌ์‹œ์ž‘ ์‹œ๊ฐ„์„ ์ •ํ™•ํ•˜๊ฒŒ ์ธก์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.


๋‹จ์–ด

  • sequence ์ˆœ์„œ
  • restoration ๋ณต๊ตฌ. ๋ถ€ํ™œ. ํšŒ๋ณต
  • specify ์ง€์ •ํ•˜๋‹ค
    • specific ํŠน์ •ํ•œ
  • anticipation ์˜ˆ์ƒ. ์˜ˆ์ธก
  • resume ๋‹ค์‹œ ์‹œ์ž‘ํ•˜๋‹ค. ์žฌ๊ฐœํ•˜๋‹ค. (๋ช…) ์ด๋ ฅ์„œ
  • periodically ์ฃผ๊ธฐ์ ์œผ๋กœ. ์ •๊ธฐ์ ์œผ๋กœ.
  • reboot ์žฌ๋ถ€ํŒ…
  • assumptions ๊ฐ€์ •
  • indeterminate ๋ถˆํ™•์‹คํ•œ. ๋ถˆํ™•์ •์˜.
  • phase ๋‹จ๊ณ„
  • manually ์ˆ˜๋™์œผ๋กœ
  • signpost ํ‘œ์ง€ํŒ (์„ ์„ธ์šฐ๋‹ค). ๋ฐฉํ–ฅ์„ ์ œ์‹œํ•˜๋‹ค.