MITB Banner

Uber Open-Sourced Piranha: A Tool To Automatically Delete Unused Codes

Share

World’s most extensive transportation network company, Uber has been engaged in powerful developing techniques to provide a great user experience. Uber has been using feature flags to customise the mobile app execution, which serves various features to different sets of users. These feature flags help in localising the user’s experience in different operating regions as well as help to roll-out features to our users and experiment with different variations of the same functionality. 

According to the researchers at Uber, in such cases, after any successful as well as unsuccessful rolling out of any features to the users, the feature flag in the code becomes obsolete or stale.

According to the developers, when a flag becomes outdated, it needs to be incapacitated in the feature flag management system. Besides, all code artefacts related to the same need should be eliminated from the source code too. These nonfunctional feature flags lead to technical issues, which in result becomes very difficult for developers to work on the codebase. Some of the drawbacks of the obsolete codes are mentioned below:

  • Unnecessary code clutter increases the overall complexity, thus reducing the productivity of developers
  • The flags can stand in the way of other experimental flags
  • Stale flags can also cause bugs
  • The unused code remains in the source as well as the binary

To mitigate such drawbacks, Uber’s researchers developed a tool that has the ability to scan source code to delete code related to stale, or obsolete feature flags known as Piranha. According to the ride-hailing giant, the tool runs in an ongoing pipeline for the Android and iOS codebases, and the developers have used it to remove around two thousand stale feature flags and their related codes.

Behind Piranha

Piranha is a tool that automatically refactors code, which are related to stale flags. This tool is an automated source-to-source code refactoring tool, which is used to automatically generate differential revisions to delete code corresponding to outdated feature flags. According to developers, this tool provides excellent utility for organisations that use feature flags in their app deployments. 

Currently, Piranha supports Objective-C, Swift, and Java programs. PiranhaJava refactors stale feature flag-related code in Java applications, specifically those targeting the Android platform. PiranhaSwift is implemented in Swift language using SwiftSyntax for refactoring Swift code and, PiranhaObjC is used to clean up code in Objective-C programs and is implemented in C++.

The developers identified three critical dimensions for performing the code cleanup, which are

  • Code that immediately borders the feature flag APIs
  • Code that becomes unreachable due to carrying out the above step. This step is also known as deep cleaning.
  • Delete tests related to feature flags

How It Works

Piranha takes as input such as the name of the flag, the name of the flag’s author and expected treatment behaviour. It then analyses the abstract syntax trees (ASTs) of the program to generate appropriate refactorings, which are packaged into a diff or differential revisions. The diff is assigned to the author of the flag for further inspection, who can then directly commit or perform any additional refactorings before committing it.

Advantages of Piranha

  • Piranha ensures improved code hygiene and avoids technical debt
  • This tool automatically refactors code related to stale flags
  • Piranha helps from application bloating and makes it easier for the developers to work on the codebase

Wrapping Up

The researchers open-sourced the tool with a motive to help out other developers who are facing similar problems. Furthermore, they want to refine the code refactorings generated by Piranha and extend it to other popular languages such as Kotlin, Go, etc.

Read the paper here.

Share
Picture of Ambika Choudhury

Ambika Choudhury

A Technical Journalist who loves writing about Machine Learning and Artificial Intelligence. A lover of music, writing and learning something out of the box.
Related Posts

CORPORATE TRAINING PROGRAMS ON GENERATIVE AI

Generative AI Skilling for Enterprises

Our customized corporate training program on Generative AI provides a unique opportunity to empower, retain, and advance your talent.

Upcoming Large format Conference

May 30 and 31, 2024 | 📍 Bangalore, India

Download the easiest way to
stay informed

Subscribe to The Belamy: Our Weekly Newsletter

Biggest AI stories, delivered to your inbox every week.

AI Courses & Careers

Become a Certified Generative AI Engineer

AI Forum for India

Our Discord Community for AI Ecosystem, In collaboration with NVIDIA. 

Flagship Events

Rising 2024 | DE&I in Tech Summit

April 4 and 5, 2024 | 📍 Hilton Convention Center, Manyata Tech Park, Bangalore

MachineCon GCC Summit 2024

June 28 2024 | 📍Bangalore, India

MachineCon USA 2024

26 July 2024 | 583 Park Avenue, New York

Cypher India 2024

September 25-27, 2024 | 📍Bangalore, India

Cypher USA 2024

Nov 21-22 2024 | 📍Santa Clara Convention Center, California, USA

Data Engineering Summit 2024

May 30 and 31, 2024 | 📍 Bangalore, India

Subscribe to Our Newsletter

The Belamy, our weekly Newsletter is a rage. Just enter your email below.