• Stars
    star
    174
  • Rank 219,104 (Top 5 %)
  • Language
    Ruby
  • License
    MIT License
  • Created about 9 years ago
  • Updated almost 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Inline frameworks of Swift CocoaPods projects for faster launch

Accelerator

Statically link CocoaPods frameworks for faster App startup

Xcode Frameworks are a good way to organise code in a large project making it easier to re-use code with a package manager such as CocoaPods. Unfortunately, from an enginering point of view breaking the program up into many small parts progressively slows application launch time as they need to be dynamically loaded one by one.

The solution is to statically link the program as a whole but as CocoaPods start to be written in Swift this would normally not be an option. Static linking would would also offer the possibility of applications using Swift pods to be deployed to iOS 7.

Stop Press:

It seems the benefit of static linking may only be manifest in the debugger if you look here. Blast.

This pod project is a proof of concept that Swift CocoaPods frameworks can be statically linked if you patch a project to perform the following steps:

  1. After pods are built, get the list of their object files using the following command:
ls -t "$OBJROOT"/Pods.build/$CONFIGURATION$EFFECTIVE_PLATFORM_NAME/*.build/Objects-normal/$CURRENT_ARCH/*.o | egrep -v "$EXCLUDED_OBJECTS_PATTERN" >"$OBJROOT"/Pods.build/$CONFIGURATION$EFFECTIVE_PLATFORM_NAME.objects.filelist
  1. Add this as a -filelist of the OTHER_LDFLAGS in the project's Pods.{debug,release}.xcconfig

  2. Substitute empty .framework files into the application package to satisfy the dynamic linker where pods themselves refer to other pods.

Setting DYLD_PRINT_STATISTICS and DYLD_PRINT_APIS on a project using 30 framework pods including swift gives the following times before patching.

    total time: 2.8 seconds (100.0%)
    total images loaded:  308 (259 from dyld shared cache)
    total segments mapped: 144, into 3741 pages with 372 pages pre-fetched
    total images loading time: 2.5 seconds (91.4%)
    total dtrace DOF registration time: 0.10 milliseconds (0.0%)
    total rebase fixups:  165,304
    total rebase fixups time: 44.22 milliseconds (1.5%)
    total binding fixups: 321,542
    total binding fixups time: 122.06 milliseconds (4.3%)
    total weak binding fixups time: 0.69 milliseconds (0.0%)
    total bindings lazily fixed up: 0 of 0
    total initializer time: 75.01 milliseconds (2.6%)

After patching to statically link the application:

    total time: 1.2 seconds (100.0%)
    total images loaded:  276 (259 from dyld shared cache)
    total segments mapped: 48, into 1143 pages with 120 pages pre-fetched
    total images loading time: 1.0 seconds (79.4%)
    total dtrace DOF registration time: 0.08 milliseconds (0.0%)
    total rebase fixups:  145,755
    total rebase fixups time: 54.68 milliseconds (4.2%)
    total binding fixups: 319,488
    total binding fixups time: 140.53 milliseconds (10.9%)
    total weak binding fixups time: 0.39 milliseconds (0.0%)
    total bindings lazily fixed up: 0 of 0
    total initializer time: 68.14 milliseconds (5.3%)

While at first glance this should lead to fast app loading time there seem to be other factors involved and one wonders whether the load times for 30-odd frameworks are going to be significant relative to the nearly 300 Apple frameworks an application links with on startup. Perhaps the most concrete benefit will be to be able to deploy to iOS7.

To use, add "pod 'Accelerator'" into your projects Podfile and type "pod update". Each time you do this, run Pods/Accelerator/patch.rb to patch the project to use static linkage. You can change the variable EXCLUDED_OBJECTS_PATTERN in the "Check Pods Manifest.lock" build phase if you encounter any problems with duplicate symbols on linking. To remove the patch remove the Accelerator" pod and update. The script has been tested with CocoaPods 0.37.2, 0.38.2 and 0.39.0.beta.3

As I say this is a POC though it does work and hopefully if the speed-up is found to be real it could be included in the CocoaPods infrastructure itself which is where it really belongs. If you have any problems or suggestions please report them using the email address support (at) injectionforxcode.com or contact me on @Injection4Xcode.

More Repositories

1

injectionforxcode

Runtime Code Injection for Objective-C & Swift
Objective-C
6,551
star
2

InjectionIII

Re-write of Injection for Xcode in (mostly) Swift
Objective-C
3,995
star
3

Xtrace

Trace Objective-C method calls by class or instance
Objective-C++
1,832
star
4

Refactorator

Xcode Plugin that Refactors Swift & Objective-C
Swift
991
star
5

GitDiff

Highlights deltas against git repo in Xcode
Objective-C
891
star
6

Remote

Control your iPhone from inside Xcode for end-to-end testing.
Objective-C
853
star
7

SwiftTrace

Trace Swift and Objective-C method invocations
Swift
695
star
8

HotReloading

Hot reloading as a Swift Package
Swift
536
star
9

XprobePlugin

Live Memory Browser for Apps & Xcode
Objective-C++
395
star
10

RefactoratorApp

App version of Refactorator plugin
Swift
255
star
11

InjectionApp

Issue Tracking Repo for Injection as an App
Swift
111
star
12

Fortify

Making Swift more robust
Swift
95
star
13

HotSwiftUI

Utilities for Hot Reloading SwiftUI apps.
Swift
94
star
14

Diamond

Diamond - Swift scripting made easy
Objective-C
94
star
15

SwiftPython

Experiments in bridging Swift to Python
Swift
88
star
16

Dynamo

High Performance (nearly)100% Swift Web server supporting dynamic content.
Swift
68
star
17

SwiftRegex

Some regular expression operators for Swift
Swift
67
star
18

NSLinux

NSString and libdispatch compatibility code for Swift on Linux
Swift
47
star
19

InstantSyntax

SwiftSyntax binary frameworks
Swift
47
star
20

InjectionNext

Fourth evolution of Code Injection for Xcode
Swift
47
star
21

WatchkitCurrency

Swift Currency Convertor for iWatch with flexible interface
Swift
40
star
22

TwoWayMirror

Adapt Swift’s Mirror functionality to make it bidirectional.
Swift
38
star
23

InjectionLite

Swift package re-write of InjectionIII app
Swift
34
star
24

Smuggler

Smuggle code bundles into an app running in the Simulator
Objective-C++
32
star
25

SwiftRegex5

5th incarnation of Swift Regex library using generic subscripts
Swift
32
star
26

SwiftAspects

Experiments in Aspects with Swift (Xtrace for Swift)
Assembly
30
star
27

unhide

export symbols with “hidden” visibility for Swift frameworks
Objective-C++
25
star
28

Symbolicate

Symbolicate for OS X
Objective-C
23
star
29

DLKit

A rather subscript oriented interface to the dynamic linker.
Swift
22
star
30

SwiftTryCatch

Try/Catch for Swift?
Swift
15
star
31

ApportablePlugin

Simple Plugin for work with Apportable
Objective-C
14
star
32

Compilertron

InjectionIII for the Swift compiler
C++
14
star
33

SearchLight

SpotLight on Steroids
Objective-C++
14
star
34

siteify

Build web site from a project’s Swift sources.
HTML
13
star
35

SwiftPlugin

A way to import classes from plugins
Swift
12
star
36

SwiftKeyPath

valueForKeyPath: for Swift
Swift
12
star
37

DynamoLinux

100% Swift Linux Web Server
Swift
11
star
38

ProfileSwiftUI

InstrumentSwiftUI
Swift
10
star
39

SwiftUIPlaygrounds

Alternative to Xcode previews.
Swift
9
star
40

SwiftRegex4

Basic regex operations for Swift4
Swift
9
star
41

StringIndex

Sensible indexing into Swift Strings
Swift
8
star
42

SwiftView

Curated Xcode Project as a means of navigating Swift Sources
7
star
43

Parallel

Some primitives for concurrent processing
Swift
6
star
44

Popen

Reading and writing processes and files
Swift
6
star
45

WatchkitSundial

Sundial for Apple Watch
Objective-C
6
star
46

SwiftierJSON

Memory efficient version of SwiftyJSON
Swift
6
star
47

objectivecpp

HTML
5
star
48

YieldGenerator

Python's "yield" generators for Swift
Swift
5
star
49

opaqueify

Greater use of Opaque types (SE0335)
Swift
5
star
50

SwiftMock

Mock structs and classes without code modification for testing.
Swift
4
star
51

Unwrap

Self documenting alternatives to force unwrap operator.
Swift
4
star
52

InjectionScratch

InjectionScratch
Objective-C++
3
star
53

EasyPointer

Rounding off some of the rough edges of Swift's pointer model
Swift
2
star
54

TestRunner

Example of calling Swift methods using name pattern (XCTest?)
Swift
2
star
55

binary-Swallow0

Swift
1
star
56

Character

Integer conversions and operators for Swift Characters.
Swift
1
star
57

ASCII

Facilitating operations on ASCII in Swift
Swift
1
star