Overview

Find unused classes within your app

Why does dead code detection and deletion matter?

Over time, dead code can accumulate until it starts to take up a real chunk of the app. This can be due to A/B test branches that are no longer used, helper classes for long-deleted features, or all other manner of things. This has the following issues:

  • Increased build time, due to compiling code that won’t be needed
  • Worse code cleanliness, with unused classes polluting the file structure, grep results, etc.
  • Longer startup time, because it will take up extra space in the binary that usually gets loaded from disk (for a deeper dive into how a binary is loaded from disk, see our blog post.

How does Reaper work? (on iOS)

Reaper is an SDK that you can put into your production or alpha users' apps to report which Swift and Objective-C classes were used for each user session. We take those reports and generate a list of all the classes in the binary, sorted by the version of the app they were last used in for at least one user session. After a few versions have been released with the SDK, the results are ready to look at. If a class hasn't been used since at least a few versions back, then in all likelihood it’s dead code that can be removed. The SDK will detect any unused classes within the main binary specifically. It's easy to integrate, either as a standalone binary or as a Cocoapod, and adds very little overhead to your app.

Performance Implications

The SDK adds less than 20kb to the binary size, and less than 1ms to startup time. The SDK will not run any code if you don't initialize it at launch. If you do initialize it, the initialization is synchronous so you can measure exactly how long it takes, we expect under 1ms.

The SDK starts running upon receiving UIApplicationDidEnterBackgroundNotification or UIApplicationWillTerminateNotification. This way it doesn't run while the user is interacting with your app. It makes one network request per notification, containing:

  1. List of used classes
  2. App bundle id
  3. App version
  4. Metadata used to identify the request on the Emerge backend

The data in this network request is compressed, and typically under 20kb but the size can vary based on how many used classes there are. The same classes are not uploaded on every notification, each class is uploaded at most once per app launch to save user data.