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

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

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.

Register for our upcoming Masterclass>>

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. 

Looking for a job change? Let us help you.

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

See Also
Orbit feature image

  • 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.

What Do You Think?

Join Our Discord Server. Be part of an engaging online community. Join Here.

Subscribe to our Newsletter

Get the latest updates and relevant offers by sharing your email.

Copyright Analytics India Magazine Pvt Ltd

Scroll To Top