Tron is a simple command-line Swift tool that provides an approximate download and installation size contribution of a set of Swift package(s) and Cocoapod(s).
Why measuring contribution of a dependency is important?
Well, we are adding a new member(dependency) to our application that is going to help us with a lot of things. Since this also adds to the binary size and given the fact that binary size is always related to the download/install experience that users go through, it's worth exploring its contribution. This analysis helps us in a lot of ways:
- It gives an approximate idea of the app size increase. If the size increase is surprising, it again opens an opportunity to collaborate and explore if there is a way to either get a thinned version of the dependency or maybe explore other dependencies for that matter, etc.
- It helps us to reason how similar dependencies stand against each other with their respective contributions to binary size.
- Peter Reinhardt has authored an amazing article that talks about the "Effect of Mobile App Size on Downloads". Please refer to the article for more details about the impact on installation rate etc.
$ git clone https://github.com/chiragramani/Tron $ cd Tron $ swift build -c release $ cd .build/release $ swift run Tron <path_to_tron_config_json_file> // follow the steps mentioned under "Run" below.
- Update tronSampleConfig.json that has information about the dependencies that you want to explore.(Swift remote + local packages as well as remote + local pods.)
- Then run
swift run Tron <path_to_tron_config_json_file>. Sample Tron Config file
Swift 5.3 or later
Xcode 12.0 or later
If measuring pods contribution, then cocoapods should be installed.
If measuring the impact on the download size,
- Before running the tool, please open the Xcode project in the Sources/Resources/iOS folder. Update the team and signing information. This is a must since a lot of this is dependent on creating an ipa successfully.
- Post the above, please update the ExportOptions.plist with your teamID and other fields as per your use-case.
Why do we have to mention minimum deployment target version in the config file ? (ABI Stability)
Swift became ABI stable with the release of Swift 5.0
- When adding Swift Package Kingfisher@6.0.0 for minimum deployment target iOS 11.3 - the following libswift dylibs are added: As we can see, 9 libswift dynamic libraries are introduced but none of them are added when the deployment target is iOS 12.2 or above.
Please note: Your application might be adding either all or a few of the above dylibs already even before the dependency is being added, so please consider the existing state. E.g. if you are importing CoreLocation already in your application- then libswiftCoreLocation.dylib will not be a new addition, and hence its contribution of ~=730 KB can be respectively subtracted from the net reported dylibs contribution.
The methodology is highly inspired by Google Cocoapods-size and does the following:
- Archive a baseline app as ARM64 with no bitcode.
- Add the required dependencies.
- Archive a baseline app as ARM64 with no bitcode.
- Compute the difference and report the respective contribution.
The size reported by Testflight is very much close (within a range of 3%) to the result calculated by following the above approach. The above approach provides a decent ballpark as far as the local analysis is concerned. A lot of things happen once the IPA is uploaded - App Store servers will be taking bitcode and app thinning into account as per your application's configuration. Post applying multiple optimizations, the servers also apply the necessary encryption with a lot of other steps before delivering the app to the user. Thus, the difference between the size that the user sees and the size that this tool reports will be different.
- How Uber Deals with Large iOS App Size The App Size Problem faced by Uber and the amazing engineering journey that resulted in some really cool code size savings.
- If you are interested in knowing the impact of every change as you make it, or if you are intrested in getting an accurate app size report on every diff or every release build, with a very detailed module by module Binary analysis breakdown, Emerge is worth exploring. How 7 iOS Apps Could Save You 500MB of Storage
Report any issues
If you run into any problems, please file a git issue. Please include:
- The OS version (e.g. macOS 10.15.6)
- The Swift version installed on your machine (from
- The Xcode version
- The specific release version of this source code (you can use
git tagto get a list of all the release versions or
git logto get a specific commit sha)
- Any local changes on your machine
- Verbose logs printed in the console when the operations were executed
Tron is licensed under MIT. See LICENSE for more information.
MIT License Copyright (c) 2021 Chirag Ramani Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.