Green Coding 3/7: native image build as path to reduce our digital carbon footprint

Thierno Diallo
Just-Tech-IT
Published in
5 min readMar 25, 2024

After introducing the fundamental basics of green coding and the sustainable data management aspect in the first two articles, which you can find at the following links:

It is time to start exploring the subjects/tools and practices that allow us to build more efficient deliverables, taking up less memory and requiring less CPU and RAM to run.

In this third part of our seven-part series, we will discuss the concept of native image compilation and its contributions to reducing our environmental impact through optimization strategies and resource reduction (energy, CPU, RAM, memory). We will quickly define native compilation, then discuss how it could help in reducing environmental impact, and finally, we will talk about its limitations.

1. Definition

Native image compilation, or “native image build,” involves compiling the source code of an application to transform it into a standalone executable binary for a target platform. The goal is to create a lightweight, optimized, standalone, and independent executable that contains everything necessary for its execution.

Several tools and frameworks are available to help us build native images, including GraalVM for Java and Kotlin, PyInstaller and Nuitka for Python. These tools allow us to build for multiple different targets.

2. Benefits of Native Image Build

Building our applications into images contributes to reducing our environmental footprint mainly through its efficiency, low memory footprint (storage and RAM) due to the small size of the executable, its optimization during deployment/startup, and the application’s execution (CPU).

Here are 7 examples of the different ways the adoption of native images can contribute to reducing our environmental footprint:

A. Efficient and optimized resource usage

Ahead of time compilation (AOT) is one of the techniques that brings the most gain to native compilation, resulting in more efficient use of CPU and RAM resources during application execution.

RAM and CPU impact

  • Native image construction uses the “Ahead of time (AOT)” compilation technique, leading to more efficient use of CPU and RAM resources during application execution.

Memory impact

Native compilation results in a reduced size of the executable and its small memory footprint, compared to JVM-based executables.

Energy consumption impact

Native image construction optimizes resource consumption during execution, leading to a reduction in energy consumption of our applications and the infrastructure on which they run.

Quick startup

Applications built in native images show a significant improvement in startup times compared to traditional applications, reducing energy needs and overall environmental impact.

Optimized containerization

Native construction produces lightweight and standalone executables, making them well-suited for containerization, reducing environmental impact associated with deployment, execution, and hosting of applications.

Reduced cooling needs and infrastructure costs

Optimization and reduced resource needs automatically lead to a reduction in cooling needs and infrastructure costs, contributing to lower environmental impact throughout the application’s lifecycle.

3. Limits of Native Image Compilation

While the advantages of native image compilation are undeniable, there are also some limitations. Depending on the final need, native compilation may not be the automatic right solution, and considerations about the volume of the app are important in choosing the compilation mode.

Understanding these limitations is necessary to know when and how to use native compilation. Here is a non-exhaustive list of some limitations:

  • Strong link with the OS
  • Complexity of debugging
  • Static configuration (mention livereload)
  • Dynamic class loading
  • Memory management complexity
  • Explicit declaration of dependencies

4. Conclusion

In summary, native image construction offers several advantages that can contribute to reducing the environmental footprint of the development and deployment of our applications. By improving resource utilization efficiency, optimizing performance, and making sustainable practices a central point, native image technology plays a crucial role in building a more environmentally friendly ecosystem.

However, it remains just one tool among many others. It should be used judiciously, in the right way according to the realities that exist, and as a complement to all the other techniques and technologies that allow us to produce more virtuous and environmentally responsible software.

At AXA France, with the generalization of CaaS (Container as a Service) (openpaas/kubernetes) as the deployment target, we have already started the practice of native compilation. Of course, we will benefit from raising awareness to better optimize our native images and disseminate this practice as widely as possible.

All of this without forgetting that this topic will necessarily lead to other subjects and initiatives such as SlimFaas and dailyclean, which are and will be widely used at AXA France, and which have a considerable impact on reducing our environmental footprint.

In the next article, we will have the opportunity to discuss green software craftsmanship and how to implement it through a practical case.

I hope this helps! Let me know if you need any further assistance.

--

--

Thierno Diallo
Just-Tech-IT

Staff Engineer/Technical Leader And Green Champion at Axa France