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

Launch Time profiler in Xcode11.

Launch Time profiler in Xcode11.

hayaishi
WWDC19 Recap at LINE
https://line.connpass.com/event/134346/

53850955f15249a1a9dc49df6113e400?s=128

LINE Developers
PRO

June 25, 2019
Tweet

Transcript

  1. Launch Time profiler in Xcode11. Hayaishi

  2. What's new? Launch timeϓϩϑΝΠϥ͕WWDC2019Ͱ঺հ͞Ε·ͨ͠. Optimizing App Launch (WWDC2019 Session)

  3. What's new? ͜ͷϓϩϑΝΠϥΛ࢖͏ͱىಈϓϩηεʹϑΥʔΧεͯ͠෼ੳ ͕Ͱ͖Δ༷ʹͳΓ·ͨ͠ɻ

  4. None
  5. Launching Speed Goal 100ms ͸SystemαΠυͷॳظԽͷͨΊʹ࢖͏࣌ؒͱͯ͠ɻ 300ms ͸ViewͷॳظԽ΍ίϯςϯπͷϩʔυͱ͍ͬͨ࣌ؒʹ ࢖͍·͢ɻ

  6. Launch Time - Profiler. • Initializing • Initializing - System

    interface Initialization ͜ͷύʔτͰ͸System SideͷॳظԽϓϩηεΛ෼ੳ͢Δ͜ͱ͕ Ͱ͖·͢ɻ
  7. Launch Time - Profiler. • Initializing - Static Runtime Initialization

    Objcͷ+loadͱ͍ͬͨॳظԽϓϩηεͷ෼ੳΛ͢Δ͜ͱ͕Ͱ͖ ·͢ɻ
  8. Launch Time - Profiler. • Launching - UIKit initialization •

    Launching - UIKit Scene Creation willFinishLaunchingWithOptions()͕࢝·Δલʹ࣮ߦ͞Εͨॲཧ Λ෼ੳ͢Δ͜ͱ͕Ͱ͖·͢ɻ
  9. Launch Time - Profiler. • Launching - willFinishLaunchingWithOptions() • Launching

    - didFinishLaunchingWithOptions()
  10. Launch Time - Profiler. • Launching Initial Frame Rendering

  11. Launch Time - Profiler. • Foreground - Active ॳظϑϨʔϜͷϨϯμϦϯάޙͷॲཧΛ෼ੳ͢Δ͜ͱ͕Ͱ͖· ͢ɻ

  12. Launch Time - Profiler. LINEͰͷ࣮ྫͰ͕͢ɺLaunch TimeϓϩϑΝΠϥͰ-100msͷແ ବͳॲཧΛൃݟ͢Δ͜ͱ͕Ͱ͖·ͨ͠ɻ private static func

    _localizedString(forKey key: String) -> String { - return NSLocalizedString(key, tableName: "{{tableName}}", bundle: ModuleBundle.bundle, comment: "") + return NSLocalizedString(key, tableName: "{{tableName}}", comment: "") }
  13. Metrics • Battery, Launch Time, Hang Rate, Memory, Disk Writes

    Xcode > Window > Organizer > Metrics
  14. Metrics

  15. Metrics ಉ༷ͷىಈ࣌ؒ͸ҎԼͷίʔυͰ΋औಘՄೳͰ͢ɻ extension ProcessInfo { var uptime: TimeInterval { return

    AbsoluteTime(time: AbsoluteTime.now) - startedTime } private var startedTime: AbsoluteTime { let pid = processIdentifier var mib = [CTL_KERN, KERN_PROC, KERN_PROC_PID, pid] var info = kinfo_proc() var size = MemoryLayout.stride(ofValue: info) let status = sysctl(&mib, numericCast(mib.count), &info, &size, nil, 0) assert(status != -1) return AbsoluteTime(time: info.kp_proc.p_starttime) } } ... let launchTimeFromProcessStarted = ProcessInfo.processInfo.uptime * 1_000 print("\(launchTimeFromProcessStarted)ms") // got a similar as a Launch Time profile.
  16. Wrap Up • Xcode11ͰϓϩϑΝΠϧΛऔͬͯΈ·͠ΐ͏ɻ(࣮ػΛ࢖ͬͯ ͍ͩ͘͞) • Launch TimeϓϩϑΝΠϧ͸ىಈϓϩηεΛ༰қʹղੳՄೳ Ͱ͢ɻ •

    ύϑΥʔϚϯεΛվળ͢Δͱ͖͸ϓϩϑΝΠϧΛΈͯɺम ਖ਼ɺϓϩϑΝΠϧΛݟΔͷ܁Γฦ͠ɻ • Xcode11 Beta͸͢Ͱʹ͍͔ͭ͘ͷMetricsΛఏڙ͍ͯ͠·