Real case study: Cocoapods vs Carthage, what’s the best package manager for you?

Marcelo Salloum dos Santos
4 min readOct 6, 2019

--

In this article, I'll show the results I've achieved by replacing my Cocoapods dependencies with Carthage ones, then I'll discuss the pros and cons of each option.

TLDR:

Carthage is like a Formula 1 car: it can run 9 times faster but needs extra preparation, extra maintenance and can’t run on any terrain.

If you aim at flexibility and at being able to quickly change your libs, Cocoapods is more like it. If you actually prefer a faster build without changing dependencies so often, then Carthage is for you.

Motivation

I’ve always used Cocoapods and couldn’t really complain about it until I started working on this project that was taking over 3 minutes to compile. After investigating it further, I've realized the project had a few dependencies that were unusually slow to compile, like Realm, AWS, RxSwift, SnapKit, Bugsnag, Kingfisher, among others.

That started annoying me and I decided to do something about it!

That's why I started experimenting with Cocoapods, Carthage, and SwiftPM. At first, I realized the problem with Cocoapods is that it builds and compiles all our frameworks every time we do a "clean build" or run `pod install`. This means that SwiftPM would not bring me any benefits on that since it also rebuilds the frameworks every time you do a clean build. Carthage, on the other hand, would build your frameworks only once and wouldn't require them to be rebuilt so often as Cocoapods does.

Do you know what that means? It means much faster builds and fewer chances of distraction!

Carthage to the rescue

When I realized that Carthage could decrease my compilation times not only for this project but for all future projects, I decided I had to see it through!

I started from a project using cocoa pods and replaced their libs, batch-by-batch, to measure how faster my build time would get. Here is a graph of it:

This graph shows my build time decreasing from 184s to 19.6s (9.28 times FASTER!) while I moved my dependencies from Cocoapods to Carthage

Yey!!!!!! I was able to reduce the compilation time from about 180s to 20s! This is 9 times faster!!!!

iOS developers getting super impressed on how faster their builds can get with Carthage.

This is sooooo awesome… maybe too awesome, right? Well, as you might have guessed at this point there ain’t no such thing as a free lunch, so which price did I have to pay?

I gotta say that not all libraries were easy to replace. AWS, for instance, takes 30 minutes to be built from Carthage since Carthage builds all the 40 AWS targets despite the fact I only need AWSS3, AWSCognito, and AWSCore. Bugsnag and Moya-ObjectMapper couldn’t even be built on Carthage and I had to either replace or incorporate their code into my project, which is definitely not ideal.

Conclusion

Alright, what do you want from a package manager? In my opinion, it should find your desired dependencies fast and succeed to install them without your help. If you agree with that definition of a "package manager", then Carthage won't make much sense to you.

I’ve successfully decreased the total compilation time from 184s to 19.6s, 9.38 times faster!

On the other hand, I’ve successfully decreased the total compilation time from 184s to 19.6s, which is 9.38 times faster! I mean, it's OVER NINE TIMES FASTER! Also, it’s harder to get distracted when you have at maximum 20s interval, especially when you compare it with a 3min interval, which is time enough for you to get distracted in an unimportant task that will take you 10 minutes to focus back on your main duty!

Vegeta couldn't believe it that Kakarot made his project over 9 times faster using Carthage.

So it all comes to “it depends”. What I mean is, if you need faster builds and won’t be changing your project’s dependencies so often, go for Carthage! If what most impacts your productivity is being able to experiment with different libs, go for the good and trustworthy Cocoapods!

Any third options?

I’m inclined to adopt a hybrid environment: using Carthage for the dependencies I’ll definitely stick with (and that take longer to build) and keeping Cocoapods under my sleeves so I can weight on its flexibility and stability.

Also, I’d like to mention two other dependencies that could start to raise the bar of this competition:

  • SwiftPM: it certainly is a very consolidated tool already, making it possible to quickly develop swift for Unix and backend applications, although I consider it a bit immature to be used in iOS production apps yet.
  • Accio (https://github.com/JamitLabs/Accio): has just been launched only a few months ago. It sounds pretty promising because it is supposed to bind SwiftPM + Carthage to make things both faster and more reliable. I'll definitely give it a try soon.

--

--