Uber’s Open Source Tool Piranha That Automatically Deletes Stale Code

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

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

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, as an example, localize the user’s experience in several regions where we operate and, more importantly, to gradually roll-out features to our users and experiment with different variations of a similar functionality.

Uber’s Open Source Tool Piranha That Automatically Deletes Stale Code

However, after a feature has either been 100 percent extended to our users or an experimental feature has been deemed unsuccessful, the feature flag within the code becomes obsolete. These non-functional feature flags represent technical debt, making it difficult for developers to figure on the codebase, and may bloat our apps, requiring unnecessary operations that impact performance for the top user and potentially impact overall app reliability.

Removing this debt are often time-intensive for our engineers, preventing them from performing on newer features.

Seeking to automate this process, we developed Piranha, a tool that scans source code to delete code associated with stale, or obsolete, feature flags, resulting in a cleaner, safer, more performant, and more maintainable code base. We run Piranha at Uber in an ongoing pipeline for our Android and iOS codebases, and have used it to get rid of around two thousand stale feature flags and their related code.

We believe Piranha offers great utility for organizations that use feature flags in their app deployments, then have open sourced it. Currently implemented for Objective-C, Swift, and Java programs, open source contributors might want to use Piranha to other languages or improve on its ability to perform deep code refactoring’s.

Behind Piranha

Piranha may be a tool that automatically refactors code, which are associated with stale flags. This tool is an automatic source-to-source code refactoring tool, which is employed to automatically generate differential revisions to delete code like outdated feature flags. Consistent with 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. Piranha Java refactors stale feature flag-related code in Java applications, specifically those targeting the Android platform. Piranha Swift is implemented in Swift language using Swift Syntax for refactoring Swift code and, Piranha ObjC is employed to wash up code in Objective-C programs and is implemented in C++. The developers identified three critical dimensions for performing the code clean-up, which are Code that immediately borders the feature flag APIs Code that becomes unreachable because of completing the above step. This step is additionally referred to as deep cleaning.

Delete tests associated with feature flags.

Advantages of Piranha

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

Piranha may be a tool to automatically refactor code associated with stale flags. At a better level, the input to the tool is that the name of the flag and therefore the expected behaviour, after specifying an inventory of APIs associated with flags during a properties file. Piranha will use these inputs to automatically refactor the code consistent with the expected behaviour.

This repository contains three independent versions of Piranha, one for every of the three supported languages: Objective-C, Swift, and Java.

To use/build each version, look under the corresponding [Lang]/ directory and follow instructions within the corresponding [Lang]/README.md file. confirm to cd into that directory to create any related code following the instructions within the README.

The Pain of Stale Code Caused By Feature Flags

Piranha the way to remove obsolete code? It also starts with a typical for Uber code.

In order to facilitate the event of system updates, Uber has adopted a feature flag, also referred to as a function switch. this is often a way that permits online functions to be controlled on or off. it’s widely utilized by major Internet companies.

Benefits of Feature Flags

Using this method has many advantages. It can complete new function tests then publish them as fully available. It also can customize differentiated services (A / B testing) for various users, and support rollback when bugs occur. Engineers also can remotely disable the faulty a part of the appliance.

According to reports, there are over 6000 function marks altogether Uber’s program code base.

But the rise of the function flag also will increase the complexity of the code base. Once the flag is out of date, you would like to delete it, otherwise it’ll bring a technical burden.

Automatically detect and delete with Piranha.

Specifically, Piranha must automatically detect obsolete signs and delete their associated code. the problem of this process is to work out whether the sign is used by someone, the owner of the sign, and understand the precise details of the code.

Considering Piranha’s application background, Uber uses application static analysis, which may be a code review to seek out obsolete code left over from obsolete signs.

Uber’s Open Source Tool Piranha That Automatically Deletes Stale Code

Use Piranha To Delete or Refactor Code

The three key dimensions which will be cleaned up are:

  • Remove the code next to the feature flags API.
  • Remove code that was inaccessible because of the previous step, called deep cleaning.
  • Delete test code associated with feature flags.

Using feature flags, companies like Uber can localize the user experience in several regions they operate. It helps Uber and other companies gradually roll-out features to users across the globe, and experiment with different variations of an equivalent functionality.

Now, these feature flags either become a successfully implemented feature or just become an unsuccessful attempt. In either case, the feature flag isn’t relevant anymore and turns into a stale feature flag.

That is precisely where developers need Piranha. This open-source tool can automatically delete these feature flags that are not any longer needed, alongside their corresponding code. Obsolete code like stale feature flags not only creates clutter within the codebase and increase its complexity but also interferes with other flags or cause bugs sometimes.

Uber’s Open Source Tool Piranha That Automatically Deletes Stale Code

The flag management system periodically sends a list of probably stale flags to Piranha, which generates a diff and sends it to the first flag author. The author can then determine whether to land the diff.

Delete The Old Code And Use Piranhas

Of course, within the introduction above, to use Piranha, the code must meet the subsequent conditions:

  • Extensive use of feature flags.
  • Has a specific API to regulate the behaviour of feature flags.
  • The code is implemented in Java, Swift, or Objective-C.
  • In addition, Piranha has other plans ongoing , like improving the refactored code generated by Piranha, and expanding Piranha to support other languages like Kotlin and Go.
  • The project is now open source and available at the subsequent address. does one want to undertake it?

Uber says it as used Piranha to get rid of around two thousand stale feature flags and their related code. The corporate recommends using Piranha in applications that use feature flags extensively and implement specific APIs to regulate their behaviour.

To read more about Piranha, you’ll ask the Uber blog and obtain it on GitHub.

Thank you for reading this article. Do let me know for any queries in comment section below.

Sharing is caring


About Author

Akash is a co-founder and an aspiring entrepreneur who keeps a close eye on open source, tech giants, and security. Get in touch with him by sending an email (akashchugh1994@gmail.com).

You may also like :-

Leave a Comment

Your email address will not be published. Required fields are marked *

Stay Connected

Popular Posts

Get Latest Stuff Through Email

Who Should Read TechTrick?

All the tricks and tips that TechTrick provides only for educational purpose. If you choose to use the information in TechTrick to break into computer systems maliciously and without authorization, you are on your own. Neither I (TechTrick Admin) nor anyone else associated with TechTrick shall be liable. We are not responsibe for any issues that caused due to informations provided here. So, Try yourself and see the results. You are not losing anything by trying... We are humans, Mistakes are quite natural. Here on TechTrick also have many mistakes..