<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">This morning I used the DYLD_PRINT_STATISTICS environment variable that was recommended in the session (I couldn’t get it to work on an iOS device, so these are numbers from the simulator). “Cold” refers to launching the app after a restart to make sure that the libraries aren’t already in memory and “hot” is when the app has been run recently. I created 2 basic iOS projects, one Swift and the other ObjC, using the empty view template, and changing nothing except the environment variable. I ran this experiment a few times over for all 4 scenarios, and these are typical results.<div class=""><br class=""></div><div class=""><b class="">Swift:</b></div><div class=""><b class="">Cold:</b></div><div class=""><font face="Menlo" class="">Total pre-main time: 140.49 milliseconds (100.0%)<br class=""> dylib loading time: 49.29 milliseconds (35.0%)<br class=""> rebase/binding time: 15.57 milliseconds (11.0%)<br class=""> ObjC setup time: 50.73 milliseconds (36.1%)<br class=""> initializer time: 24.72 milliseconds (17.5%)<br class=""> slowest intializers :<br class=""> libSystem.dylib : 7.22 milliseconds (5.1%)<br class=""> libBacktraceRecording.dylib : 8.49 milliseconds (6.0%)<br class=""> CoreFoundation : 3.41 milliseconds (2.4%)<br class=""> Foundation : 4.42 milliseconds (3.1%)</font></div><div class=""><b class="">Hot:</b></div><div class=""><div class=""><font face="Menlo" class="">Total pre-main time: 63.33 milliseconds (100.0%)<br class=""> dylib loading time: 27.78 milliseconds (43.8%)<br class=""> rebase/binding time: 11.38 milliseconds (17.9%)<br class=""> ObjC setup time: 13.25 milliseconds (20.9%)<br class=""> initializer time: 10.83 milliseconds (17.1%)<br class=""> slowest intializers :<br class=""> libSystem.dylib : 2.46 milliseconds (3.8%)<br class=""> libBacktraceRecording.dylib : 4.84 milliseconds (7.6%)<br class=""> Foundation : 1.52 milliseconds (2.4%)</font></div><div class=""><div class=""><br class="webkit-block-placeholder"></div><div class=""><b class="">ObjC:</b></div><div class=""><b class="">Cold:</b></div><div class=""><font face="Menlo" class="">Total pre-main time: 133.77 milliseconds (100.0%)<br class=""> dylib loading time: 43.62 milliseconds (32.6%)<br class=""> rebase/binding time: 14.08 milliseconds (10.5%)<br class=""> ObjC setup time: 51.98 milliseconds (38.8%)<br class=""> initializer time: 23.88 milliseconds (17.8%)<br class=""> slowest intializers :<br class=""> libSystem.dylib : 6.52 milliseconds (4.8%)<br class=""> libBacktraceRecording.dylib : 7.93 milliseconds (5.9%)<br class=""> CoreFoundation : 3.89 milliseconds (2.9%)<br class=""> Foundation : 4.32 milliseconds (3.2%)</font></div><div class=""><b class="">Hot:</b></div><div class=""><font face="Menlo" class="">Total pre-main time: 55.55 milliseconds (100.0%)<br class=""> dylib loading time: 21.90 milliseconds (39.4%)<br class=""> rebase/binding time: 11.30 milliseconds (20.3%)<br class=""> ObjC setup time: 12.92 milliseconds (23.2%)<br class=""> initializer time: 9.34 milliseconds (16.8%)<br class=""> slowest intializers :<br class=""> libSystem.dylib : 2.98 milliseconds (5.3%)<br class=""> libBacktraceRecording.dylib : 3.52 milliseconds (6.3%)<br class=""> CoreFoundation : 1.23 milliseconds (2.2%)<br class=""> Foundation : 1.15 milliseconds (2.0%)</font></div><div class=""><br class="webkit-block-placeholder"></div><div class="">Keep in mind that the recommended startup time is 400ms. The Swift standard libraries never show up in slowest initializers, but something does seem to be slowing the Swift startup time down at least a little, but not by a significant amount. My conclusion would be that the Swift libs are indeed optimized and shouldn’t be a major concern.</div><div class=""><br class=""></div><div class="">However, my bigger concern was in an app that has 3rd party dependencies (like my own). I’m looking at a 700ms pre-main time, with all my Carthage dependencies showing up in the slowest initializers list. While some of them could be refactored out, others are either non-simple, or for a service we use such as analytics. I’m curious how we can optimize the launch time of a Swift app that uses 3rd party frameworks, since iOS doesn’t support static linking of Swift code.</div><div class=""><br class=""></div><div class="">Interestingly, Crashlytics uses a framework, with a module map, that can be used by Swift code directly, but the binary is a static lib that doesn’t need to be embedded. I wonder how they created that...</div><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; font-variant-ligatures: normal; font-variant-position: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; line-height: normal; border-spacing: 0px;"><div class=""><br class="Apple-interchange-newline"><b style="font-size: 18px;" class="">David Beck</b></div><div style="font-weight: normal;" class=""><a href="http://davidbeck.co" class="">http://davidbeck.co</a></div><div style="font-weight: normal;" class=""><a href="http://twitter.com/davbeck" class="">http://twitter.com/davbeck</a></div><div style="font-weight: normal;" class=""><a href="http://facebook.com/davbeck" class="">http://facebook.com/davbeck</a></div></span></div>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On Jun 18, 2016, at 8:41 AM, David Beck <<a href="mailto:swift@tnku.co" class="">swift@tnku.co</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">In session 406: optimizing app startup time at WWDC, most of the recommendations were very pro Swift. Things like using structs and the fact that it can automatically inline calls. One recommendation that was very anti swift, was the section on limiting dylibs. The presenter recommended keeping it to under 6. I’m not sure if the 15 libswift dylibs that get included by default in a Swift application count towards that (he did mention that Apple frameworks are optimized, but I’m not sure if that is limited to the ones preinstalled on the device).<div class=""><br class=""></div><div class="">His recommendation was to use static libraries, which makes sense, except that Swift on iOS doesn’t seem to support static linking. But for whatever reason, Swift PM ONLY supports static linking. <b class="">Is there any plans to add static linking to Mac and iOS apps?</b> The only alternative I see at this point is to simply include the source files from libraries in the app’s target, but Swift has from the beginning encouraged naming things generically and relying on modules for name spacing.<br class=""><div class="">
<div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-style: normal; font-variant-ligatures: normal; font-variant-position: normal; font-variant-caps: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div class=""><br class="Apple-interchange-newline"><b style="font-size: 18px;" class="">David Beck</b></div><div style="font-weight: normal;" class=""><a href="http://davidbeck.co/" class="">http://davidbeck.co</a></div><div style="font-weight: normal;" class=""><a href="http://twitter.com/davbeck" class="">http://twitter.com/davbeck</a></div><div style="font-weight: normal;" class=""><a href="http://facebook.com/davbeck" class="">http://facebook.com/davbeck</a></div></span></div>
</div>
<br class=""></div></div></div></blockquote></div><br class=""></div></div></body></html>