While using a CI server to compile and run my tests, I realized that it takes about 30 minutes to run my unit tests and UI tests suite. My app is not that big and the CI tasks to run are quite simple. 30 minutes is quite insane.
While looking through the CI logs, I notice that building the app takes a very long time. When looking into it more, I realized that cocoapods is one big reason why my app takes so long to build. Cocoapods does not pre-compile your dependencies for you so each time you build, they get built too.
There are other factors in there too such as XCode settings and how long the compiler takes to compile your code. The XCode settings we don't need to worry about because with the latest swift compiler and XCode build system improvements, the defaults work pretty well from what I have read. I do need to improve my code in my app I am sure of it. I have never looked into this before. Here are some resources to learn more about how to do that 1, 2
But anyway lets get back to cocoapods. To improve the build speed of my app with my dependencies, you can do a few things:
Keep your dependencies down as low as possible. A given. The less code to compile, the better. I am looking at ways to do this anyway.
Use pre-built frameworks. Cocoapods will make your project compile the source code of your dependencies along with your own source code when you build your app. Others like Carthage and Swift Package Manager will instead pre-build your dependencies into binary frameworks that you can then include in XCode project. Then when your code compiles, the frameworks are already built!
Carthage seems like a way to go right now because it's been around in the community. But, there are some issues. The biggest being some frameworks, like firebase, have experimental support at this time. Firebase also said that they will not make official support for it because they plan to make SPM official instead.
Many of the popular libraries I use are ready to use in SPM. I am thinking that's the way to go since that's where the community wants to go. It pre-compiles binaries and can get code directly from github like carthage does which means we don't need a centralized server for downloading and installing dependencies which is neat, too.
I am thinking about this plan:
[ ] Keep cocoapods installed for some of those libraries that are a huge pain to install without it (firebase).
[ ] Use SPM for libraries that I can use it for. Not sure if it will help, but this and this make it seem like we can use both cocoapods and SPM in the same project.
In the end, we will be switching over to using pre-built frameworks.
I attempted to do this recently. Here were my findings:
You can use SPM and cocoapods in the same project. Just remove entries from the Podfile you want to install via SPM and then in XCode, add SPM package to it via the UI.
Moya seemed to work well. I was able to install it via SPM. But when it came to RxSwift, I had issues. Specially when trying to run UITests there were errors about "RxCocoaRuntime" module not being found. I couldn't find a fix that seemed to work well for me. There are have been SPM bugs filled saying that it's not working. There are GitHub issues created for RxSwift project, but they are all closed saying that it's SPM issue.
While using a CI server to compile and run my tests, I realized that it takes about 30 minutes to run my unit tests and UI tests suite. My app is not that big and the CI tasks to run are quite simple. 30 minutes is quite insane.
While looking through the CI logs, I notice that building the app takes a very long time. When looking into it more, I realized that cocoapods is one big reason why my app takes so long to build. Cocoapods does not pre-compile your dependencies for you so each time you build, they get built too.
There are other factors in there too such as XCode settings and how long the compiler takes to compile your code. The XCode settings we don't need to worry about because with the latest swift compiler and XCode build system improvements, the defaults work pretty well from what I have read. I do need to improve my code in my app I am sure of it. I have never looked into this before. Here are some resources to learn more about how to do that 1, 2
But anyway lets get back to cocoapods. To improve the build speed of my app with my dependencies, you can do a few things:
Carthage seems like a way to go right now because it's been around in the community. But, there are some issues. The biggest being some frameworks, like firebase, have experimental support at this time. Firebase also said that they will not make official support for it because they plan to make SPM official instead.
Many of the popular libraries I use are ready to use in SPM. I am thinking that's the way to go since that's where the community wants to go. It pre-compiles binaries and can get code directly from github like carthage does which means we don't need a centralized server for downloading and installing dependencies which is neat, too.
I am thinking about this plan:
In the end, we will be switching over to using pre-built frameworks.