BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News How Uber Deals with Unreachable Code Associated to Feature Flags in its Mobile Apps

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

This item in japanese

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, Piranha periodically queries the flag management system to know which flags have become stale, and then it generates a diff that 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 needing improvements, according to its creators. However, it proved to be effective among Uber's engineers in order to automate the process of paying out techical flag debt.

Rate this Article

Adoption
Style

BT