3

I have project in Swift and when I measure with DYLD_PRINT_STATISTICS I can see 1.0 second pre-init time, where 70% is dynamic libraries linking.

Are there any clean and safe ways of dealing with this problem?

Eric Aya
  • 68,765
  • 33
  • 165
  • 232
Roma
  • 1,087
  • 8
  • 18
  • Cocoapods I think, do you use that? – J. Doe Jul 29 '17 at 11:17
  • It is likely linked frameworks. Without more specific information, I can't give a more specific answer. That said, the [WWDC 2017 Session](https://developer.apple.com/videos/play/wwdc2017/413/) on this is quite instructive. – Brandon Bradley Jul 29 '17 at 13:02
  • @J.Doe cocoapods indeed. but if i add libraries manually it wont solve the problem because dynamic linking will be there one way or another. I've came across solution to transform all pods to static library. But that does not look as clean solution on my opinion – Roma Jul 29 '17 at 18:59
  • @BrandonBradley thank you for the link I will check it out. What info could be helpful ? I will provide it – Roma Jul 29 '17 at 19:00
  • @Roma It occurred to me that it's highly unlikely that you're running the macOS High Sierra beta, which is what the session is about (my bad). Instead, I'd recommend [Optimizing App Startup Time](https://developer.apple.com/videos/play/wwdc2016/406/) from last year's WWDC. The most useful part of this talk probably starts at 27:30. The session walks through a too slow app, and speeds it up dramatically. As far as specifics go, I was referring to the number of libraries, raw launch time, whether or not an ObjC / C++ is used, and if you have access to the library source code. – Brandon Bradley Jul 29 '17 at 20:12
  • @BrandonBradley thank you for the second link. I do understand that my problem is in cocopods and dylib. So, thing to figure out is how to make it work better together – Roma Jul 29 '17 at 20:33

1 Answers1

1

According to Apple's WWDC 2016 Session on Optimizing App Startup Time, regardless of their size, having a large number of dynamically linked libraries slows down app launch time dramatically.

To fix this, several dynamic libraries can be merged into a single library. If they are already static libraries, then libtool can be used to combine them, using the command from this SO answer. However, if they are not static, then to combine them, one must have access to their source code. If the source code is accessible, then literally copying the code from one library into another, and using the resulting library, will suffice.

Of course, merging disparate libraries into a single one is definitely inconvenient from the developer's perspective. To combat this, Xcode allows for different libraries to be linked when different flags (i.e. RELEASE and DEBUG) are set, as described in this forum.

When possible, it's better to merge static libraries, as the merging process is far less error prone. CocoaPods allows users to use static libraries in their projects.

Brandon Bradley
  • 2,100
  • 2
  • 17
  • 37
  • 1
    Note that loading time has been improved since them. Delaying the loading of dylibs instead referencing the whole app from your appdelegate decreases the time the app needs to become responsive. – Jano Feb 19 '18 at 16:54