•App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present,...

194
#WWDC17 © 2017 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. Louis Gerbarg, Senior Linker Engineer App Startup Time: Past, Present, and Future Session 413 Developer

Transcript of •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present,...

Page 1: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

#WWDC17

© 2017 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

Louis Gerbarg, Senior Linker Engineer

•App Startup Time: Past, Present, and Future • Session 413

Developer

Page 2: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

•Review of app launch startup advice •New tools to help find slow initializers •Brief history of dyld •The all new dyld that is coming in this years Apple OS platforms

•Best practices

Page 3: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preamble

Page 4: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preamble

We want your feedback

Page 5: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preamble

We want your feedback• Please file bug reports with “DYLD USAGE:” in the title

Page 6: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preamble

We want your feedback• Please file bug reports with “DYLD USAGE:” in the title

Terminology

Page 7: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preamble

We want your feedback• Please file bug reports with “DYLD USAGE:” in the title

Terminology• Startup time

Page 8: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preamble

We want your feedback• Please file bug reports with “DYLD USAGE:” in the title

Terminology• Startup time

- For the purposes of this talk startup time is everything that happens before main() is called

Page 9: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preamble

We want your feedback• Please file bug reports with “DYLD USAGE:” in the title

Terminology• Startup time

- For the purposes of this talk startup time is everything that happens before main() is called

• Launch Closure

Page 10: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preamble

We want your feedback• Please file bug reports with “DYLD USAGE:” in the title

Terminology• Startup time

- For the purposes of this talk startup time is everything that happens before main() is called

• Launch Closure- All of the information necessary to launch an application

Page 11: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Improving App Startup Time

Optimizing App Startup Time WWDC 2016

Page 12: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Improving App Startup Time

Do less!

Optimizing App Startup Time WWDC 2016

Page 13: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Improving App Startup Time

Do less!• Embed fewer dylibs

Optimizing App Startup Time WWDC 2016

Page 14: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Improving App Startup Time

Do less!• Embed fewer dylibs• Declare fewer classes/methods

Optimizing App Startup Time WWDC 2016

Page 15: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Improving App Startup Time

Do less!• Embed fewer dylibs• Declare fewer classes/methods• Use fewer initializers

Optimizing App Startup Time WWDC 2016

Page 16: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Improving App Startup Time

Do less!• Embed fewer dylibs• Declare fewer classes/methods• Use fewer initializers

Use more Swift

Optimizing App Startup Time WWDC 2016

Page 17: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Improving App Startup Time

Do less!• Embed fewer dylibs• Declare fewer classes/methods• Use fewer initializers

Use more Swift• No initializers

Optimizing App Startup Time WWDC 2016

Page 18: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Improving App Startup Time

Do less!• Embed fewer dylibs• Declare fewer classes/methods• Use fewer initializers

Use more Swift• No initializers• Swift size improvements

Optimizing App Startup Time WWDC 2016

Page 19: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Improving App Startup Time Static initializer tracing

NEW

Page 20: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Improving App Startup Time Static initializer tracing

New in iOS 11 and macOS High Sierra

NEW

Page 21: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Improving App Startup Time Static initializer tracing

New in iOS 11 and macOS High Sierra

Provides precise timing for each static initializer

NEW

Page 22: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Improving App Startup Time Static initializer tracing

New in iOS 11 and macOS High Sierra

Provides precise timing for each static initializer

Available through Instruments

NEW

Page 23: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Improving App Startup Time Static initializer tracing

New in iOS 11 and macOS High Sierra

Provides precise timing for each static initializer

Available through Instruments

NEW

Page 24: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

•Demo

Page 25: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages dyld 1.0 (1996–2004)

Page 26: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages dyld 1.0 (1996–2004)

Shipped in NeXTStep 3.3

Page 27: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages dyld 1.0 (1996–2004)

Shipped in NeXTStep 3.3

Predated POSIX dlopen() standardized

Page 28: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages dyld 1.0 (1996–2004)

Shipped in NeXTStep 3.3

Predated POSIX dlopen() standardized• Third-party wrapper functions

Page 29: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages dyld 1.0 (1996–2004)

Shipped in NeXTStep 3.3

Predated POSIX dlopen() standardized• Third-party wrapper functions

Before most systems used large C++ dynamic libraries

Page 30: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages dyld 1.0 (1996–2004)

Shipped in NeXTStep 3.3

Predated POSIX dlopen() standardized• Third-party wrapper functions

Before most systems used large C++ dynamic libraries

Prebinding added in macOS Cheetah (10.0)

Page 31: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages dyld 2.0 (2004–2007)

Page 32: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages dyld 2.0 (2004–2007)

Shipped in macOS Tiger

Page 33: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages dyld 2.0 (2004–2007)

Shipped in macOS Tiger

Complete rewrite

Page 34: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages dyld 2.0 (2004–2007)

Shipped in macOS Tiger

Complete rewrite• Correct C++ initializer semantics

Page 35: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages dyld 2.0 (2004–2007)

Shipped in macOS Tiger

Complete rewrite• Correct C++ initializer semantics• Full native dlopen()/dlsym() semantics

Page 36: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages dyld 2.0 (2004–2007)

Shipped in macOS Tiger

Complete rewrite• Correct C++ initializer semantics• Full native dlopen()/dlsym() semantics

Designed for speed

Page 37: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages dyld 2.0 (2004–2007)

Shipped in macOS Tiger

Complete rewrite• Correct C++ initializer semantics• Full native dlopen()/dlsym() semantics

Designed for speed• Limited sanity checking

Page 38: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages dyld 2.0 (2004–2007)

Shipped in macOS Tiger

Complete rewrite• Correct C++ initializer semantics• Full native dlopen()/dlsym() semantics

Designed for speed• Limited sanity checking• Security “Issues”

Page 39: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages dyld 2.0 (2004–2007)

Shipped in macOS Tiger

Complete rewrite• Correct C++ initializer semantics• Full native dlopen()/dlsym() semantics

Designed for speed• Limited sanity checking• Security “Issues”

Reduced prebinding

Page 40: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages dyld 2.x (2007–2017)

Page 41: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages dyld 2.x (2007–2017)

More architectures and platforms

Page 42: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages dyld 2.x (2007–2017)

More architectures and platforms• x86, x86_64, arm, arm64

Page 43: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages dyld 2.x (2007–2017)

More architectures and platforms• x86, x86_64, arm, arm64• iOS, tvOS, watchOS

Page 44: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages dyld 2.x (2007–2017)

More architectures and platforms• x86, x86_64, arm, arm64• iOS, tvOS, watchOS

Improved security

Page 45: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages dyld 2.x (2007–2017)

More architectures and platforms• x86, x86_64, arm, arm64• iOS, tvOS, watchOS

Improved security• Codesigning, ASLR, bounds checking

Page 46: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages dyld 2.x (2007–2017)

More architectures and platforms• x86, x86_64, arm, arm64• iOS, tvOS, watchOS

Improved security• Codesigning, ASLR, bounds checking

Improved performance

Page 47: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages dyld 2.x (2007–2017)

More architectures and platforms• x86, x86_64, arm, arm64• iOS, tvOS, watchOS

Improved security• Codesigning, ASLR, bounds checking

Improved performance• Prebinding completely replaced by shared cache

Page 48: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages Shared Cache

Page 49: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages Shared Cache

Introduced in iOS 3.1 and macOS Snow Leopard

Page 50: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages Shared Cache

Introduced in iOS 3.1 and macOS Snow Leopard• Replaced prebinding

Page 51: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages Shared Cache

Introduced in iOS 3.1 and macOS Snow Leopard• Replaced prebinding

Single file that contains most system dylibs

Page 52: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages Shared Cache

Introduced in iOS 3.1 and macOS Snow Leopard• Replaced prebinding

Single file that contains most system dylibs• Rearranges binaries to improve load speed

Page 53: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages Shared Cache

Introduced in iOS 3.1 and macOS Snow Leopard• Replaced prebinding

Single file that contains most system dylibs• Rearranges binaries to improve load speed• Pre-links dylibs

Page 54: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages Shared Cache

Introduced in iOS 3.1 and macOS Snow Leopard• Replaced prebinding

Single file that contains most system dylibs• Rearranges binaries to improve load speed• Pre-links dylibs• Pre-builds data structures used dyld and ObjC

Page 55: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages Shared Cache

Introduced in iOS 3.1 and macOS Snow Leopard• Replaced prebinding

Single file that contains most system dylibs• Rearranges binaries to improve load speed• Pre-links dylibs• Pre-builds data structures used dyld and ObjC

Built locally on macOS, shipped as part of all other Apple OS platforms

Page 56: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages dyld 3 (2017)

Page 57: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages dyld 3 (2017)

Announcing it today

Page 58: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages dyld 3 (2017)

Announcing it today

Complete rethink of dynamic linking

Page 59: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages dyld 3 (2017)

Announcing it today

Complete rethink of dynamic linking

On by default for most macOS system apps in this weeks seed

Page 60: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages dyld 3 (2017)

Announcing it today

Complete rethink of dynamic linking

On by default for most macOS system apps in this weeks seed

Will be on be the default for system apps for 2017 Apple OS platforms

Page 61: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Dynamic Linking Through the Ages dyld 3 (2017)

Announcing it today

Complete rethink of dynamic linking

On by default for most macOS system apps in this weeks seed

Will be on be the default for system apps for 2017 Apple OS platforms

Will completely replace dyld 2.x in future Apple OS platforms

Page 62: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Why?

Page 63: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Why?

Performance

Page 64: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Why?

Performance• What is the minimum amount of work we can do to start an app?

Page 65: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Why?

Performance• What is the minimum amount of work we can do to start an app?

Security

Page 66: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Why?

Performance• What is the minimum amount of work we can do to start an app?

Security• Can we have more aggressive security checks?

Page 67: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Why?

Performance• What is the minimum amount of work we can do to start an app?

Security• Can we have more aggressive security checks?

Reliability

Page 68: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Why?

Performance• What is the minimum amount of work we can do to start an app?

Security• Can we have more aggressive security checks?

Reliability• Can we design something that is easier to test?

Page 69: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 How?

Page 70: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 How?

Move complex operations out of process

Page 71: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 How?

Move complex operations out of process• Most of dyld is now a regular daemon

Page 72: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 How?

Move complex operations out of process• Most of dyld is now a regular daemon

Make the rest of dyld as small as possible

Page 73: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 How?

Move complex operations out of process• Most of dyld is now a regular daemon

Make the rest of dyld as small as possible• Reduces attack surface

Page 74: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 How?

Move complex operations out of process• Most of dyld is now a regular daemon

Make the rest of dyld as small as possible• Reduces attack surface• Speeds up launch

Page 75: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 How?

Move complex operations out of process• Most of dyld is now a regular daemon

Make the rest of dyld as small as possible• Reduces attack surface• Speeds up launch

- The fastest code is code you never write

Page 76: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 How?

Move complex operations out of process• Most of dyld is now a regular daemon

Make the rest of dyld as small as possible• Reduces attack surface• Speeds up launch

- The fastest code is code you never write- Followed closely by code you almost

never execute

Page 77: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 How?

Move complex operations out of process• Most of dyld is now a regular daemon

Make the rest of dyld as small as possible• Reduces attack surface• Speeds up launch

- The fastest code is code you never write- Followed closely by code you almost

never execute

dyld 2

Page 78: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 How?

Move complex operations out of process• Most of dyld is now a regular daemon

Make the rest of dyld as small as possible• Reduces attack surface• Speeds up launch

- The fastest code is code you never write- Followed closely by code you almost

never execute

Parse mach-o headers

dyld 2

Page 79: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 How?

Move complex operations out of process• Most of dyld is now a regular daemon

Make the rest of dyld as small as possible• Reduces attack surface• Speeds up launch

- The fastest code is code you never write- Followed closely by code you almost

never execute

Parse mach-o headers

Find dependencies

dyld 2

Page 80: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 How?

Move complex operations out of process• Most of dyld is now a regular daemon

Make the rest of dyld as small as possible• Reduces attack surface• Speeds up launch

- The fastest code is code you never write- Followed closely by code you almost

never execute

Parse mach-o headers

Find dependencies

Map mach-o files

dyld 2

Page 81: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 How?

Move complex operations out of process• Most of dyld is now a regular daemon

Make the rest of dyld as small as possible• Reduces attack surface• Speeds up launch

- The fastest code is code you never write- Followed closely by code you almost

never execute

Parse mach-o headers

Find dependencies

Map mach-o files

Perform symbol lookups

dyld 2

Page 82: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 How?

Move complex operations out of process• Most of dyld is now a regular daemon

Make the rest of dyld as small as possible• Reduces attack surface• Speeds up launch

- The fastest code is code you never write- Followed closely by code you almost

never execute

Parse mach-o headers

Find dependencies

Map mach-o files

Perform symbol lookups

Bind and rebase

dyld 2

Page 83: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 How?

Move complex operations out of process• Most of dyld is now a regular daemon

Make the rest of dyld as small as possible• Reduces attack surface• Speeds up launch

- The fastest code is code you never write- Followed closely by code you almost

never execute

Parse mach-o headers

Find dependencies

Map mach-o files

Perform symbol lookups

Bind and rebase

Run initializers

dyld 2

Page 84: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Perform symbol lookups

Find dependencies

Parse mach-o headersParse mach-o headers

Find dependencies

Map mach-o files

Bind and rebase

Run initializers

dyld 2

dyld 3 How?

Perform symbol lookups

Page 85: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Perform symbol lookups

Find dependencies

Parse mach-o headersParse mach-o headers

Find dependencies

Identify security sensitive components

Map mach-o files

Bind and rebase

Run initializers

dyld 2

dyld 3 How?

Perform symbol lookups

Page 86: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Perform symbol lookups

Find dependencies

Parse mach-o headersParse mach-o headers

Find dependencies

Identify security sensitive components

Map mach-o files

Bind and rebase

Run initializers

dyld 2

dyld 3 How?

Perform symbol lookups

Page 87: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Perform symbol lookups

Find dependencies

Parse mach-o headersParse mach-o headers

Find dependencies

Identify security sensitive components• Bounds checking

Map mach-o files

Bind and rebase

Run initializers

dyld 2

dyld 3 How?

Perform symbol lookups

Page 88: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Perform symbol lookups

Find dependencies

Parse mach-o headersParse mach-o headers

Find dependencies

Identify security sensitive components• Bounds checking• @rpath confusion attacks

Map mach-o files

Bind and rebase

Run initializers

dyld 2

dyld 3 How?

Perform symbol lookups

Page 89: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Perform symbol lookups

Find dependencies

Parse mach-o headersParse mach-o headers

Find dependencies

Identify security sensitive components• Bounds checking• @rpath confusion attacks

Identify components that are cache-ableMap mach-o files

Bind and rebase

Run initializers

dyld 2

dyld 3 How?

Perform symbol lookups

Page 90: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Perform symbol lookups

Find dependencies

Parse mach-o headersParse mach-o headers

Find dependencies

Identify security sensitive components• Bounds checking• @rpath confusion attacks

Identify components that are cache-able• Dependencies don’t change

between launches

Map mach-o files

Bind and rebase

Run initializers

dyld 2

dyld 3 How?

Perform symbol lookups

Page 91: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Perform symbol lookups

Find dependencies

Parse mach-o headersParse mach-o headers

Find dependencies

Identify security sensitive components• Bounds checking• @rpath confusion attacks

Identify components that are cache-able• Dependencies don’t change

between launches• Symbol locations within a mach-o do not

change between launches

Map mach-o files

Bind and rebase

Run initializers

dyld 2

dyld 3 How?

Perform symbol lookups

Page 92: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Parse mach-o headers

Find dependencies

Map mach-o files

Bind and rebase

Run initializers

dyld 2

dyld 3 How?

Perform symbol lookups

Page 93: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

Parse mach-o headers

Find dependencies

Map mach-o files

Bind and rebase

Run initializers

dyld 2

Perform symbol lookups

Page 94: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3

dyld 3 Architecture

Parse mach-o headers

Find dependencies

Map mach-o files

Bind and rebase

Run initializers

dyld 2

Perform symbol lookups

Parse mach-o headers

Find dependencies

Map mach-o files

Bind and rebase

Run initializers

Perform symbol lookups

Page 95: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3

Write closure to disk

Read in closure

Validate closure

dyld 3 Architecture

Parse mach-o headers

Find dependencies

Map mach-o files

Bind and rebase

Run initializers

dyld 2

Perform symbol lookupsParse mach-o headers

Find dependencies

Map mach-o files

Bind and rebase

Run initializers

Perform symbol lookups

Page 96: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

Parse mach-o headers

Find dependencies

Perform symbol lookups

dyld 3

Map mach-o files

Bind and rebase

Run initializers

Write closure to disk

Read in closure

Validate closure

Page 97: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

dyld 3 has 3 components Parse mach-o headers

Find dependencies

Perform symbol lookups

dyld 3

Map mach-o files

Bind and rebase

Run initializers

Write closure to disk

Read in closure

Validate closure

Page 98: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

dyld 3 has 3 components• An out of process MachO parser/compiler

Parse mach-o headers

Find dependencies

Perform symbol lookups

dyld 3

Map mach-o files

Bind and rebase

Run initializers

Write closure to disk

Read in closure

Validate closure

Page 99: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

dyld 3 has 3 components• An out of process MachO parser/compiler• An in-process engine that runs launch

closures

Parse mach-o headers

Find dependencies

Perform symbol lookups

dyld 3

Map mach-o files

Bind and rebase

Run initializers

Write closure to disk

Read in closure

Validate closure

Page 100: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

dyld 3 has 3 components• An out of process MachO parser/compiler• An in-process engine that runs launch

closures• A launch closure caching service

Parse mach-o headers

Find dependencies

Perform symbol lookups

dyld 3

Map mach-o files

Bind and rebase

Run initializers

Write closure to disk

Read in closure

Validate closure

Page 101: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

dyld 3 has 3 components• An out of process MachO parser/compiler• An in-process engine that runs launch

closures• A launch closure caching service

Most launches use the cache and never invoke the out-of-process mach-o parser/compiler

Parse mach-o headers

Find dependencies

Perform symbol lookups

dyld 3

Map mach-o files

Bind and rebase

Run initializers

Write closure to disk

Read in closure

Validate closure

Page 102: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

dyld 3 has 3 components• An out of process MachO parser/compiler• An in-process engine that runs launch

closures• A launch closure caching service

Most launches use the cache and never invoke the out-of-process mach-o parser/compiler• Launch closures are simpler than mach-o

Parse mach-o headers

Find dependencies

Perform symbol lookups

dyld 3

Map mach-o files

Bind and rebase

Run initializers

Write closure to disk

Read in closure

Validate closure

Page 103: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

dyld 3 has 3 components• An out of process MachO parser/compiler• An in-process engine that runs launch

closures• A launch closure caching service

Most launches use the cache and never invoke the out-of-process mach-o parser/compiler• Launch closures are simpler than mach-o• Launch closures are built for speed

Parse mach-o headers

Find dependencies

Perform symbol lookups

dyld 3

Map mach-o files

Bind and rebase

Run initializers

Write closure to disk

Read in closure

Validate closure

Page 104: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

Parse mach-o headers

Find dependencies

Perform symbol lookups

dyld 3

Map mach-o files

Bind and rebase

Run initializers

Write closure to disk

Read in closure

Validate closure

Page 105: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

dyld 3 is an out-of-process mach-o parser Parse mach-o headers

Find dependencies

Perform symbol lookups

dyld 3

Map mach-o files

Bind and rebase

Run initializers

Write closure to disk

Read in closure

Validate closure

Page 106: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

dyld 3 is an out-of-process mach-o parser• Resolves all search paths, @rpaths,

environment variables

Parse mach-o headers

Find dependencies

Perform symbol lookups

dyld 3

Map mach-o files

Bind and rebase

Run initializers

Write closure to disk

Read in closure

Validate closure

Page 107: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

dyld 3 is an out-of-process mach-o parser• Resolves all search paths, @rpaths,

environment variables• Parses the mach-o binaries

Parse mach-o headers

Find dependencies

Perform symbol lookups

dyld 3

Map mach-o files

Bind and rebase

Run initializers

Write closure to disk

Read in closure

Validate closure

Page 108: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

dyld 3 is an out-of-process mach-o parser• Resolves all search paths, @rpaths,

environment variables• Parses the mach-o binaries• Performs all symbol lookups

Parse mach-o headers

Find dependencies

Perform symbol lookups

dyld 3

Map mach-o files

Bind and rebase

Run initializers

Write closure to disk

Read in closure

Validate closure

Page 109: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

dyld 3 is an out-of-process mach-o parser• Resolves all search paths, @rpaths,

environment variables• Parses the mach-o binaries• Performs all symbol lookups• Creates a launch closure with results

Parse mach-o headers

Find dependencies

Perform symbol lookups

dyld 3

Map mach-o files

Bind and rebase

Run initializers

Write closure to disk

Read in closure

Validate closure

Page 110: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

dyld 3 is an out-of-process mach-o parser• Resolves all search paths, @rpaths,

environment variables• Parses the mach-o binaries• Performs all symbol lookups• Creates a launch closure with results• Is a normal daemon that can use normal

testing infrastructure

Parse mach-o headers

Find dependencies

Perform symbol lookups

dyld 3

Map mach-o files

Bind and rebase

Run initializers

Write closure to disk

Read in closure

Validate closure

Page 111: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

Parse mach-o headers

Find dependencies

Perform symbol lookups

dyld 3

Map mach-o files

Bind and rebase

Run initializers

Write closure to disk

Read in closure

Validate closure

Page 112: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

dyld 3 is a small in-process engine Parse mach-o headers

Find dependencies

Perform symbol lookups

dyld 3

Map mach-o files

Bind and rebase

Run initializers

Write closure to disk

Read in closure

Validate closure

Page 113: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

dyld 3 is a small in-process engine• Validates launch closure

Parse mach-o headers

Find dependencies

Perform symbol lookups

dyld 3

Map mach-o files

Bind and rebase

Run initializers

Write closure to disk

Read in closure

Validate closure

Page 114: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

dyld 3 is a small in-process engine• Validates launch closure• Maps in all dylibs

Parse mach-o headers

Find dependencies

Perform symbol lookups

dyld 3

Map mach-o files

Bind and rebase

Run initializers

Write closure to disk

Read in closure

Validate closure

Page 115: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

dyld 3 is a small in-process engine• Validates launch closure• Maps in all dylibs• Applies fixups

Parse mach-o headers

Find dependencies

Perform symbol lookups

dyld 3

Map mach-o files

Bind and rebase

Run initializers

Write closure to disk

Read in closure

Validate closure

Page 116: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

dyld 3 is a small in-process engine• Validates launch closure• Maps in all dylibs• Applies fixups• Runs initializers

Parse mach-o headers

Find dependencies

Perform symbol lookups

dyld 3

Map mach-o files

Bind and rebase

Run initializers

Write closure to disk

Read in closure

Validate closure

Page 117: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

dyld 3 is a small in-process engine• Validates launch closure• Maps in all dylibs• Applies fixups• Runs initializers• Jumps to main()

Parse mach-o headers

Find dependencies

Perform symbol lookups

dyld 3

Map mach-o files

Bind and rebase

Run initializers

Write closure to disk

Read in closure

Validate closure

Page 118: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

dyld 3 is a small in-process engine• Validates launch closure• Maps in all dylibs• Applies fixups• Runs initializers• Jumps to main()

Never needs to parse mach-o headers or access the symbol tables

Parse mach-o headers

Find dependencies

Perform symbol lookups

dyld 3

Map mach-o files

Bind and rebase

Run initializers

Write closure to disk

Read in closure

Validate closure

Page 119: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

Page 120: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

dyld 3 is a launch closure cache

Page 121: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

dyld 3 is a launch closure cache• System app launch closures built into shared cache

Page 122: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

dyld 3 is a launch closure cache• System app launch closures built into shared cache• Third-party app launch closures built during install

Page 123: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

dyld 3 is a launch closure cache• System app launch closures built into shared cache• Third-party app launch closures built during install

- Rebuilt during software update

Page 124: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

dyld 3 is a launch closure cache• System app launch closures built into shared cache• Third-party app launch closures built during install

- Rebuilt during software update• On macOS the in process engine can call out to a daemon if necessary

Page 125: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

dyld 3 Architecture

dyld 3 is a launch closure cache• System app launch closures built into shared cache• Third-party app launch closures built during install

- Rebuilt during software update• On macOS the in process engine can call out to a daemon if necessary

- Not necessary on other Apple OS platforms

Page 126: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Potential issues

Page 127: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Potential issues

Fully compatible with dyld 2.x

Page 128: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Potential issues

Fully compatible with dyld 2.x• Some existing APIs disable dyld 3’s optimizations or require slow fallback paths

Page 129: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Potential issues

Fully compatible with dyld 2.x• Some existing APIs disable dyld 3’s optimizations or require slow fallback paths• Some existing optimizations done for dyld 2.x no longer have any impact

Page 130: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Potential issues

Fully compatible with dyld 2.x• Some existing APIs disable dyld 3’s optimizations or require slow fallback paths• Some existing optimizations done for dyld 2.x no longer have any impact

Stricter linking semantics

Page 131: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Potential issues

Fully compatible with dyld 2.x• Some existing APIs disable dyld 3’s optimizations or require slow fallback paths• Some existing optimizations done for dyld 2.x no longer have any impact

Stricter linking semantics• Workarounds for old binaries

Page 132: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Potential issues

Fully compatible with dyld 2.x• Some existing APIs disable dyld 3’s optimizations or require slow fallback paths• Some existing optimizations done for dyld 2.x no longer have any impact

Stricter linking semantics• Workarounds for old binaries• New binaries will cause linker errors

Page 133: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Unaligned pointers in __DATA

Page 134: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Unaligned pointers in __DATA

When you have a global struct it is placed in the data segment

Page 135: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Unaligned pointers in __DATA

When you have a global struct it is placed in the data segment• Unaligned pointers in the struct will be embedded in the __DATA segment

Page 136: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Unaligned pointers in __DATA

When you have a global struct it is placed in the data segment• Unaligned pointers in the struct will be embedded in the __DATA segment

Fixing up unaligned pointers is more complex

Page 137: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Unaligned pointers in __DATA

When you have a global struct it is placed in the data segment• Unaligned pointers in the struct will be embedded in the __DATA segment

Fixing up unaligned pointers is more complex• Can span multiple pages

Page 138: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Unaligned pointers in __DATA

When you have a global struct it is placed in the data segment• Unaligned pointers in the struct will be embedded in the __DATA segment

Fixing up unaligned pointers is more complex• Can span multiple pages• Can have atomicity issues

Page 139: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Unaligned pointers in __DATA

When you have a global struct it is placed in the data segment• Unaligned pointers in the struct will be embedded in the __DATA segment

Fixing up unaligned pointers is more complex• Can span multiple pages• Can have atomicity issues

The static linker already emits a warning

Page 140: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Unaligned pointers in __DATA

When you have a global struct it is placed in the data segment• Unaligned pointers in the struct will be embedded in the __DATA segment

Fixing up unaligned pointers is more complex• Can span multiple pages• Can have atomicity issues

The static linker already emits a warningld: warning: pointer not aligned at address 0x10056E59C

Page 141: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

struct ListHead { };

#pragma pack(1) // Changes default alignment globally struct List { uint32_t count; // 4 bytes @ 0x0 struct ListElement *head; // 8 bytes @ 0x4: MISALIGNED!! } __attribute__((__packed__, aligned(1))); // Changes alignment for this struct

static struct ListElement sHead; struct List gList = {0, &sHead}; //pointer not aligned at address 0x100001004 (_gList + 4 from ...)

Page 142: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

struct ListHead { };

#pragma pack(1) // Changes default alignment globally struct List { uint32_t count; // 4 bytes @ 0x0 struct ListElement *head; // 8 bytes @ 0x4: MISALIGNED!! } __attribute__((__packed__, aligned(1))); // Changes alignment for this struct

static struct ListElement sHead; struct List gList = {0, &sHead}; //pointer not aligned at address 0x100001004 (_gList + 4 from ...)

Page 143: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

struct ListHead { };

#pragma pack(1) // Changes default alignment globally struct List { uint32_t count; // 4 bytes @ 0x0 struct ListElement *head; // 8 bytes @ 0x4: MISALIGNED!! } __attribute__((__packed__, aligned(1))); // Changes alignment for this struct

static struct ListElement sHead; struct List gList = {0, &sHead}; //pointer not aligned at address 0x100001004 (_gList + 4 from ...)

Page 144: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

struct ListHead { };

#pragma pack(1) // Changes default alignment globally struct List { uint32_t count; // 4 bytes @ 0x0 struct ListElement *head; // 8 bytes @ 0x4: MISALIGNED!! } __attribute__((__packed__, aligned(1))); // Changes alignment for this struct

static struct ListElement sHead; struct List gList = {0, &sHead}; //pointer not aligned at address 0x100001004 (_gList + 4 from ...)

Page 145: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Eager symbol resolution

Page 146: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Eager symbol resolution

dyld 2 performs lazy symbol resolution

Page 147: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Eager symbol resolution

dyld 2 performs lazy symbol resolution• Symbol lookups are too expensive to do them up front

Page 148: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Eager symbol resolution

dyld 2 performs lazy symbol resolution• Symbol lookups are too expensive to do them up front• Each symbol is looked up the first time you call it

Page 149: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Eager symbol resolution

dyld 2 performs lazy symbol resolution• Symbol lookups are too expensive to do them up front• Each symbol is looked up the first time you call it• Missing symbols cause a crash the first time they are called

Page 150: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Eager symbol resolution

dyld 2 performs lazy symbol resolution• Symbol lookups are too expensive to do them up front• Each symbol is looked up the first time you call it• Missing symbols cause a crash the first time they are called

dyld 3 performs eager symbol resolutions

Page 151: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Eager symbol resolution

dyld 2 performs lazy symbol resolution• Symbol lookups are too expensive to do them up front• Each symbol is looked up the first time you call it• Missing symbols cause a crash the first time they are called

dyld 3 performs eager symbol resolutions• Since all symbol lookups are cached it is very fast

Page 152: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Eager symbol resolution

dyld 2 performs lazy symbol resolution• Symbol lookups are too expensive to do them up front• Each symbol is looked up the first time you call it• Missing symbols cause a crash the first time they are called

dyld 3 performs eager symbol resolutions• Since all symbol lookups are cached it is very fast• Makes it possible to check if all symbols are present

Page 153: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Eager symbol resolution

Page 154: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Eager symbol resolution

Apps built against current SDKs will run with unknown symbols

Page 155: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Eager symbol resolution

Apps built against current SDKs will run with unknown symbols• Identical behavior to dyld 2, on first call it

will crash

Page 156: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Eager symbol resolution

Apps built against current SDKs will run with unknown symbols• Identical behavior to dyld 2, on first call it

will crash

Apps built against future SDKs will fail to launch with unknown symbols

Page 157: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Eager symbol resolution

Apps built against current SDKs will run with unknown symbols• Identical behavior to dyld 2, on first call it

will crash

Apps built against future SDKs will fail to launch with unknown symbols• Can simulate behavior today with

-bind_at_load linker flag

Page 158: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Eager symbol resolution

Apps built against current SDKs will run with unknown symbols• Identical behavior to dyld 2, on first call it

will crash

Apps built against future SDKs will fail to launch with unknown symbols• Can simulate behavior today with

-bind_at_load linker flag• Only use on test builds, not release

Page 159: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 dlopen()/dlsym()/dladdr()

Page 160: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 dlopen()/dlsym()/dladdr()

Still have problematic semantics

Page 161: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 dlopen()/dlsym()/dladdr()

Still have problematic semantics• Still necessary in some cases

Page 162: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 dlopen()/dlsym()/dladdr()

Still have problematic semantics• Still necessary in some cases

Symbols found with dlsym() must be found at runtime

Page 163: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 dlopen()/dlsym()/dladdr()

Still have problematic semantics• Still necessary in some cases

Symbols found with dlsym() must be found at runtime• Cannot be pre-linked by dyld 3

Page 164: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 dlopen()/dlsym()/dladdr()

Still have problematic semantics• Still necessary in some cases

Symbols found with dlsym() must be found at runtime• Cannot be pre-linked by dyld 3

We are working on better alternatives

Page 165: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 dlopen()/dlsym()/dladdr()

Still have problematic semantics• Still necessary in some cases

Symbols found with dlsym() must be found at runtime• Cannot be pre-linked by dyld 3

We are working on better alternatives• Want to hear about your use cases

Page 166: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 dlopen()/dlsym()/dladdr()

Still have problematic semantics• Still necessary in some cases

Symbols found with dlsym() must be found at runtime• Cannot be pre-linked by dyld 3

We are working on better alternatives• Want to hear about your use cases• Not going away, but may be slower in dyld 3

Page 167: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 dlclose()

Page 168: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 dlclose()

Misnomer

Page 169: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 dlclose()

Misnomer• Decrements a refcount, does not necessarily close the dylib

Page 170: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 dlclose()

Misnomer• Decrements a refcount, does not necessarily close the dylib• Not appropriate for resource management

Page 171: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 dlclose()

Misnomer• Decrements a refcount, does not necessarily close the dylib• Not appropriate for resource management

Features that prevent a dylib from unloading

Page 172: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 dlclose()

Misnomer• Decrements a refcount, does not necessarily close the dylib• Not appropriate for resource management

Features that prevent a dylib from unloading• Objective-C classes

Page 173: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 dlclose()

Misnomer• Decrements a refcount, does not necessarily close the dylib• Not appropriate for resource management

Features that prevent a dylib from unloading• Objective-C classes• Swift classes

Page 174: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 dlclose()

Misnomer• Decrements a refcount, does not necessarily close the dylib• Not appropriate for resource management

Features that prevent a dylib from unloading• Objective-C classes• Swift classes• C __thread and C++ thread_local variables

Page 175: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 dlclose()

Misnomer• Decrements a refcount, does not necessarily close the dylib• Not appropriate for resource management

Features that prevent a dylib from unloading• Objective-C classes• Swift classes• C __thread and C++ thread_local variables

Considering making dlclose() a no-op everywhere except macOS

Page 176: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 all_image_infos

Page 177: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 all_image_infos

Interface for introspecting dylibs in a process

Page 178: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 all_image_infos

Interface for introspecting dylibs in a process• Struct in memory

Page 179: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 all_image_infos

Interface for introspecting dylibs in a process• Struct in memory• Wastes a lot of memory

Page 180: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 all_image_infos

Interface for introspecting dylibs in a process• Struct in memory• Wastes a lot of memory• Going away in future releases

Page 181: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 all_image_infos

Interface for introspecting dylibs in a process• Struct in memory• Wastes a lot of memory• Going away in future releases• We will be providing replacement APIs

Page 182: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 all_image_infos

Interface for introspecting dylibs in a process• Struct in memory• Wastes a lot of memory• Going away in future releases• We will be providing replacement APIs• Please let us know how you use it

Page 183: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Best Practices

Page 184: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Best Practices

Make sure your app launches when built with -bind_at_load added to LD_FLAGS

Page 185: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Best Practices

Make sure your app launches when built with -bind_at_load added to LD_FLAGS• Debug builds only

Page 186: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Best Practices

Make sure your app launches when built with -bind_at_load added to LD_FLAGS• Debug builds only

Fix any unaligned pointers in your app’s __DATA segment

Page 187: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Best Practices

Make sure your app launches when built with -bind_at_load added to LD_FLAGS• Debug builds only

Fix any unaligned pointers in your app’s __DATA segmentld: warning: pointer not aligned at address 0x100001004

Page 188: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Best Practices

Make sure your app launches when built with -bind_at_load added to LD_FLAGS• Debug builds only

Fix any unaligned pointers in your app’s __DATA segmentld: warning: pointer not aligned at address 0x100001004

Make sure you are not depending on terminators running when you call dlclose()

Page 189: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Best Practices

Make sure your app launches when built with -bind_at_load added to LD_FLAGS• Debug builds only

Fix any unaligned pointers in your app’s __DATA segmentld: warning: pointer not aligned at address 0x100001004

Make sure you are not depending on terminators running when you call dlclose()

Let us know why you are using dlopen()/dlsym()/dladdr()/all_image_infos

Page 190: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Preparing for dyld 3 Best Practices

Make sure your app launches when built with -bind_at_load added to LD_FLAGS• Debug builds only

Fix any unaligned pointers in your app’s __DATA segmentld: warning: pointer not aligned at address 0x100001004

Make sure you are not depending on terminators running when you call dlclose()

Let us know why you are using dlopen()/dlsym()/dladdr()/all_image_infos• File bug reports with “DYLD USAGE:” in their titles

Page 191: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

More Informationhttps://developer.apple.com/wwdc17/413

Page 192: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Related Sessions

Optimizing App Startup Time WWDC 2016

Page 193: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •

Labs

Optimizing App Startup Time Lab Technology Lab E Fri 11:00AM–12:30PM

Page 194: •App Startup Time: Past, Present, and Future - Apple Inc. file•App Startup Time: Past, Present, and Future • Session 413 Developer • Review of app launch startup advice •