Mobile Monitoring Solutions

Search
Close this search box.

How Uber Deals With Unreachable Code Associated to Feature Flags in its Mobile Apps

MMS Founder
MMS Sergio De Simone

Article originally posted on InfoQ. Visit InfoQ

Piranha is a newly open-sourced tool by Uber that can be used to remove stale code in mobile apps written in Java, Objective-C, or Swift for Android and iOS. The tool was born with the aim to pay technical debt ensuing from the process of implementing and eventually removing feature flags, says Uber.

Feature flags are a great way to experiment with new features. For example, using feature flags you can roll out new features in a controlled way, or you can roll out different variations of a new feature to different user groups to better assess their experience. In addition, feature flags make it possible to quickly roll back a new feature that proved to be buggy or is not well accepted by your user base.

One important aspect of feature flag that is not often discussed, explains Uber engineer Murali Krishna Ramanathan, is technical debt, which can become quite large when feature flags are used extensively. The issue of technical debt arises when a feature flag comes to end of life, for example because a feature’s gradual roll-out was completed, or because a feature was finally cancelled. When a feature flag becomes stale, all the code that implements it, as well all code that has become unreachable due to that flag removal, should be cleaned up:

Surprisingly, refactoring code and eliminating technical debt due to stale flags can be a non-trivial task. Our experience has shown that this is due to a confluence of diverse problems:

  • sub-optimal flag management that makes information on staleness of flag to be ambiguous,
  • churn in the organization affecting flag ownership, and
  • lack of developer incentives to cleanup source code related to the flags.

Uber engineers have come to manage over 6,000 flags across multiple apps and the time spent to clean up the code associated to obsolete flags could hinder developers from working on new flags, adds Ramanathan.

Piranha works at the abstract syntax tree (AST) level to detect a number of patterns that are usually associated to feature flags. Piranha is based on the use of specific annotations to identify feature flags in the code and on a flag management system to fully automate the process of stale code cleanup. To streamline the process for engineers, iranha periodically queries the flag management system to know which flags have become stale then it generates a diff which is sent to the flag owner for review.

Uber found out that over 75% of all diffs generated by Piranha are effectively processed by engineers. Oddly, almost 95% of Objective-C diffs and 75% of Swift diffs are processed, while only round 55% of Java diffs are. This may be explained with the fact that Java diffs Piranha generates require more manual effort than either Swift or Objective-C diffs. Also, the more stringent app size requirements the App Store imposes on over-the-air updates adds to iOS engineers motivation to reduce their app binary sizes. Similarly, Piranha generates diffs that pass continuous integration testing with varying results depending on the language, with Objective-C diffs being almost always (99.41%) correct, and Java diffs the least (71.46%).

Piranha is not a perfect solution to the problem of stale flags and it has areas of improvements, according to its creators, but it proved to be effective among Uber’s engineer to automate the process of paying out techical flag debt.

Subscribe for MMS Newsletter

By signing up, you will receive updates about our latest information.

  • This field is for validation purposes and should be left unchanged.