Mobile Development 18 min read

How We Cut iOS Incremental Build Time by 75% with SPM and a Three‑Layer Architecture

Facing 200‑second peak compile times, the FoxFriend iOS team replaced CocoaPods with Swift Package Manager and introduced a three‑layer interface‑implementation‑service architecture, reducing average incremental builds from 120 seconds to 50 seconds, saving 3.1 developer‑hours per day and achieving a 58% overall compile‑time reduction.

Sohu Tech Products
Sohu Tech Products
Sohu Tech Products
How We Cut iOS Incremental Build Time by 75% with SPM and a Three‑Layer Architecture

Background

As the FoxFriend app grew, iOS incremental compilation peaked at 200 seconds and averaged 120 seconds, severely hurting developer efficiency.

Problem

Increasing module count and complex inter‑module dependencies caused exponential compile‑time growth; any change in a module forced recompilation of all dependent modules.

Existing Solutions

Traditional architectures (MVC, MVVM, VIPER) ignore compile‑time impact. Large‑scale solutions like ByteDance’s JoJo (bazel‑based) require massive infrastructure investment.

Proposed Approach

Adopt Swift Package Manager (SPM) to replace CocoaPods and design a three‑layer architecture (Interface, Implementation, Service) that isolates dependencies.

SPM vs CocoaPods

Dimension

CocoaPods

SPM

Decision Basis

Dependency resolution efficiency

Global lock O(n²)

Topological sort O(n)

Speed gap >10× when modules >100

Module isolation

Weak (global headers)

Strong (target‑based)

Eliminate implicit dependencies

Compilation cache support

Coarse‑grained (whole pod)

Fine‑grained (single file/module)

Foundation for incremental builds

Apple ecosystem integration

Third‑party maintenance

Official Apple support

Long‑term technical benefit

Three‑Layer Architecture

Interface Layer defines public protocols only, acting as an ABI firewall that prevents downstream modules from depending on implementation details.

Implementation Layer provides concrete classes marked internal, hidden from other modules.

Service Layer uses a lightweight DI container (Factory 2.0) to resolve protocols at runtime, decoupling interface from implementation.

Implementation Details

Use SPM for module isolation; each module declares dependencies via public protocol and public struct/enum.

Register protocol‑implementation mappings in Injection.swift files.

Resolve instances with Factory.resolve(UserProtocol.self).

Verification

Two test apps were built: MainApp1 (traditional) and MainApp2 (three‑layer). Modifying the implementation of a leaf module in MainApp2 triggered recompilation only for that module, while MainApp1 recompiled dependent modules as well.

Measured incremental compile time reduced by ~600 ms (35 % improvement) in the test scenario.

Results in Production

Average incremental compile time dropped from 120 s to 50 s (58 % reduction).

Peak compile time reduced from 200 s to 50 s.

Daily developer time saved ≈ 3.1 hours.

Branch‑merge time shortened from 2–3 h to 30 min.

Componentization increased to 115 SPM modules (95 % Swift).

ROI

One‑time effort of ~95 person‑days yields a payback period of about 9 months, after which the efficiency gains become net profit.

Conclusion

Replacing CocoaPods with SPM and enforcing a three‑layer interface isolation dramatically improves iOS build performance and developer productivity without massive infrastructure investment.

iOSbuild optimizationdependency-injectionmodular architectureincremental-compilationSwift Package Manager
Sohu Tech Products
Written by

Sohu Tech Products

A knowledge-sharing platform for Sohu's technology products. As a leading Chinese internet brand with media, video, search, and gaming services and over 700 million users, Sohu continuously drives tech innovation and practice. We’ll share practical insights and tech news here.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.