BE A CODE OPTIMIZATION GURU TO REDUCE CO2 EMISSION

BE A CODE OPTIMIZATION GURU TO REDUCE CO2 EMISSION

Developing a code needs to be looked at climate change lenses since Antarctica is losing ice mass (melting) at an average rate of about 150 billion tons per year, and Greenland is losing about 270 billion tons per year, adding to sea level rise according to NASA. A little contribution from every developer can lead to better CO2 reduction through optimized battery usage.

Common Myth

While talking to majority of the developers, a pattern that is common across majority of the teams that a clean code is the target to reach sustainability but it is not the case always.

Piece of code written with best practices and reviewed by number of peers are always good for a healthy and maintainable system but it should be analysed on code optimization lenses to upgrade to a sustainable eco-system;

No alt text provided for this image
Clean code need not be a sustainable code

A iOS app calls 3000 micro-services can always be clean code but not a sustainable solution when it can be reduced to 30 micro-services calls with the help of reusable components. But this kind of optimization is not possible without measuring resource utilization of current code.

Where to Start?

Measuring current state of application through tools that capture co2 measurement from application along with performance measurement tools of customer behavior

If you can't measure CO2 emission, you can't make it to a sustainable code.

Step 1: Monitor Battery using AccuBattery

Running android apps with battery monitoring mechanism such as Accubattery app helps to tracking progress of overall energy utilization (either with other apps opened or isolated way)

No alt text provided for this image
Accubattery screen

But this is not good enough for an android developer to understand overall pattern of battery usage in different resources and categories. Hence Battery Historian in Docker helps developers with better insights of unnecessary energy usage from different part of application.

Similar exercise is possible in settings > battery of iOS phones to understand current usage of battery from different apps.


Knowing how much battery being used from target application is the beginning but capturing such metrics for periodic releases helps to track increase/decrease in energy usage. Next step is to actively monitor the code for economical conception of energy!


Step 2: Automated Code Scan using ecoCode-SonarQube and Jenkins

No alt text provided for this image

ecoCode is a popular plugin that helps in scanning the application code as a plugin through SonarQube and ecoCode-mobile is the key step for mobile applications to scan for SAST (Static Application Security Test) using SonarQube to track eco-conception tags within code smells to monitor/fix code usage with best practices to reduce CO2 emission.

In my experience, ecoCode failing to give any useful insights related to co2 emission but it helps in implementing some code best practices such as global variables by simply filtering the results with 'eco-conception' flag. Hence something better than nothing!

Step 3: Optimize the code and be a Sustainability Guru!

"Code shrinking (also known as tree shaking), is the process of removing code that R8 determines is not required at runtime. This process can greatly reduce your app's size if, for example, your app includes many library dependencies but utilizes only a small part of their functionality. " Reference: Link

Optimizing Code through tree shaking, efficient app storage file size reduction are helpful while building the app towards green future. In my experience, more than one direction required to look at the code in order to,

  1. Reduce energy usage that reduce the energy bills of your users
  2. Reduce app storage size that optimizes server and hardware usage
  3. Reduce unnecessary micro service calls that improves user experience and reduce battery usage
  4. Reduce memory usage that helps avoiding unnecessary app crashes.

No alt text provided for this image
Four Pillars of Sustainable App Development

My Leadership Experience on Software Sustainability

Both pandemic and economic turbulence made us to think about energy bills in every aspect and my experience with sustainability start with 'SustainableOps' as a cultural transformation to engineering teams. Unless the culture and mindset changed, nothing can be adapted in the direction of Green Code!

80% of my initial efforts were spent in directing 300+ engineers towards and enabling their learning with best-in-class courses across online sources such as CISL from University of Cambridge and Microsoft.

When engineers learnt the basics of CO2e, ESG Score, I had to take a fast tracked approach to lead them to key problems of sustainability such as Device Resource Utilization to facilitate modernized innovations-all these were possible by referring to some best sellers collection(will share more highlights in upcoming editions) that resulted in implementing some cutting edge technologies into native app development.


Important Step : Green User Stories !

Fundamental challenge in any engineering team is that the sustainability awareness getting missed while team initiating a new beginning to app development hence it leads to excess electricity usage through battery and it leads to increased CO2 emission. Making sure to include principles in of User Stories (if you develop applications in agile teams) helps in looking at in everything we do from to in SDLC. There are great references available from Green Software Foundation to make a start today!

No alt text provided for this image
Banner to promote Green Software Development to take a pledge!

Feel free to and with your thoughts. Like this article? Subscribe to Engineering Leadership and Digital Payments Hub to enjoy reading useful articles.

Disclaimer: Contents, posts and media used in this account of the author do not represent any organisation of any sort. Under no circumstances will the author be held responsible or liable in any way for any claims, loss, expenses or liabilities whatsoever.

Hari Krishna Chandaluri .

Functional Head l Core Banking l Internet Banking l Mobile Banking l Agent Banking l AML

1 年

Great opportunity

KRISHNAN N NARAYANAN

Sales Associate at American Airlines

1 年

Great opportunity

要查看或添加评论,请登录

社区洞察

其他会员也浏览了