All the sessions from Transform 2021 are available on-demand now. Watch now.
Uber today made available in open source Piranha, a tool that automatically deletes stale and unused code from app codebases. The company says it eliminates the need for engineers to engage in the task of code removal themselves, which often prevents them from working on newer features.
Concretely, Piranha could help businesses that maintain apps speed up their development lifecycle, which in turn could cut down on costs and improve end-user experiences.
“At Uber, we use feature flags to customize our mobile app execution, serving different features to different sets of users. These flags allow us to, for example, localize the user’s experience in different regions where we operate and, more importantly, to gradually roll-out features to our users and experiment with different variations of the same functionality,” wrote Uber in a blog post. “However, after a feature has either been 100% rolled out to our users or an experimental feature has been deemed unsuccessful, the feature flag in the code becomes obsolete. These nonfunctional feature flags represent technical debt, making it difficult for developers to work on the codebase, and can bloat our apps, requiring unnecessary operations that impact performance for the end user and potentially impact overall app reliability.”
Piranha, then, scans source code in Objective-C, Swift, and Java to delete code related to obsolete feature flags, in theory producing a cleaner, more performant, and more maintainable codebase. Uber says it runs Piranha in an ongoing pipeline for its Android and iOS codebases, and that the tool has been used to remove around two thousand stale feature flags and related code to date.
Piranha takes as input the name of the flag, the expected treatment behavior, and the name of the flag’s author. Then, it analyzes the abstract syntax trees of the program to generate refactorings (changes in code structure that don’t impact behavior) that are packaged into what’s called a diff and marks code paths for deletion. The diff is assigned to the author of the flag for further inspection, who can commit changes to the master codebase or perform additional refactorings if necessary.
Uber notes that Piranha can be used either as a standalone tool or as part of a pipeline. In the pipeline configuration, it queries a flag management system for a list of stale flags and for each provides the name of the stale flag, its owner, and the intended output behavior. Piranha generates a diff and puts it up in a code review system with the flag’s original author as the default reviewer. (The author can either accept the diff as is, modify it as needed, or reject and mark the flag as not being stale.) And it generates a cleanup task to track the status of each generated diff, with a reminder bot — PiranhaTidy — that periodically adds reminders on open Piranha-related tasks.
Piranha pipelines use a heuristic to consider flags that are unmodified in the flag management system for more than a specific period (e.g., 8 weeks) and to generate diffs for those flags. Individual teams responsible for processing Piranha’s output diffs configure the exact time period for staleness of a flag.
According to Uber, Piranha can process millions of lines of code and takes less than 3 minutes to generate a diff on average. As of today, it’s available for code that uses feature flags extensively and that has specific APIs to control the behavior of feature flags. “We welcome developer contributions for Piranha,” continued Uber. “Developers of all abilities are welcome, and working on the implementation of Piranha may be a great way to understand the nuances of program analysis for non-experts in the area.”
VentureBeatVentureBeat's mission is to be a digital town square for technical decision-makers to gain knowledge about transformative technology and transact. Our site delivers essential information on data technologies and strategies to guide you as you lead your organizations. We invite you to become a member of our community, to access:
- up-to-date information on the subjects of interest to you
- our newsletters
- gated thought-leader content and discounted access to our prized events, such as Transform 2021: Learn More
- networking features, and more