Mobile Development 6 min read

Efficient Identification and Removal of Unused Code in Large-Scale Mobile Projects

The article discusses the challenges of locating dead or low‑utilization code in rapidly evolving mobile applications and presents a practical framework that combines Xcode code coverage with an automated UI testing platform and a gateway layer to achieve accurate online coverage without invasive instrumentation.

Ctrip Technology
Ctrip Technology
Ctrip Technology
Efficient Identification and Removal of Unused Code in Large-Scale Mobile Projects

Author Bio Jiang Ruidong joined Ctrip in 2009, worked on wireless R&D, and now leads hotel wireless development within the large accommodation business group.

Cleaning unused code is a crucial daily task; regular removal keeps the codebase concise and logic clear, preventing future pitfalls.

Traditional approaches rely on scripts or IDE features to find unreferenced methods or classes, and some open‑source algorithms can detect duplicate or similar code.

However, with Ctrip’s hotel business expanding rapidly, the codebase has ballooned and iteration cycles have accelerated, making these simple techniques insufficient for timely dead‑code detection.

Because of massive server‑ and client‑side experiments and frequent feature toggles, manual inspection cannot reliably identify unused code, especially when app size constraints are strict. The research focus thus becomes how to efficiently locate dead or rarely used code.

The first idea is to examine online code coverage; uncovered sections are potential dead code.

Typical online coverage uses instrumentation (inserting probes into every function) and a backend algorithm to calculate coverage, but this approach is invasive and computationally heavy.

Instead, the team leverages Xcode’s built‑in Code Coverage tool, which visualizes coverage and execution frequency without modifying production code.

While the report clearly shows which code paths are exercised, Xcode’s coverage only works during unit tests, which rely on mock data and cannot fully reflect real‑world hotel scenarios.

The team therefore turned to their automated testing platform, which can replay real traffic from logs, covering millions of cases and approximating production behavior.

They designed a workflow where UI test cases send empty requests to the platform; the platform randomly selects matching responses from the log database and returns them to the client, iterating enough times to cover most cases.

This approach theoretically provides a viable framework, but a single page often depends on dozens of micro‑services with data inter‑dependencies, which the platform cannot fully simulate.

To address this, both the UI tests and the automated testing platform were refactored: a gateway mimicking the production environment was placed before the automated service APIs to handle JSON‑to‑protobuf protocol conversion.

With this gateway, unit tests require only minimal changes—redirecting the production gateway address to the test gateway—allowing a full‑page test with just a few lines of code.

Consequently, the team obtained a complete framework for measuring online code coverage via periodic automated UI cases, delivering realistic coverage metrics for the live codebase.

Mobile developmentcode coverageiOSsoftware engineeringautomated testingdead code
Ctrip Technology
Written by

Ctrip Technology

Official Ctrip Technology account, sharing and discussing growth.

0 followers
Reader feedback

How this landed with the community

login 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.