Useful Techniques for Developing Sustainable Software

Note

This article encompasses and summarizes various approaches for developing energy-aware software. If you read this, we assume that you are familiar with basic aspects of coding and software development already.


Faster generally means more energy efficient

It is natural to think that computers "work harder" to get the job done faster. However, in reality, it is often the opposite — doing things faster means doing fewer things. More precisely, faster computing allows the processor to idle for longer periods of time. By idling, we mean going to more efficient energy state (you can read more about energy states here). Even if the difference is not noticeable to the user, it is not an excuse for not optimising the code since the difference in power consumption may be quite noticeable.

Data efficiency

Sending data between processor and memory via the data bus is much costlier regarding energy than operating with it within the CPU. Using disk IO is even worse. Use processor caching as much as possible; and try to reduce the data movement in general, i.e. use disk IO only when it is necessary.

Less loops, more events

Quite often the algorithm needs to check whether a certain condition in another part of the program has been met to continue working. There are two main ways to do it: polling and event system. The polling technique is constantly fetching the state of some variables and performs logical operations using them. An event system is an opposite — when something happens in the code, other parts which depend on it get notified.

For greener software, you should avoid using polling as much as you can, especially if checking the condition involves fetching something from memory. The only exception is when you know that using polling would be more efficient as the condition is not going to be checked too many times. In this case, or if you have to use polling for some other reason, you should try to reduce its frequency.

Decrease the system timer frequency

When software does something periodically, it needs a timer. Reducing the rate of the system timer is often necessary for applications to run smoothly. However, it is less energy efficient as well.

Fig. 1: Power impact of increasing Periodic Timer resolution (1)

Use increased timer rate only when necessary and swiftly turn it back to normal.

Low-level programming

The high-level programming languages, such as Java and Python, are designed mainly for easier usage and readability. Although not as performant as low-level languages, they allow writing programs swiftly and making sure that these programs are robust and maintainable. These are the main requirements for today's software, as powerful hardware takes care of most of the performance issues. Hence, almost all of the software products today are written with high-level code.

The usability comes at the cost of performance because "high-level" means a high level of abstraction — mainly, from hardware. However, as stated earlier, increasing software efficiency will inevitably lead to saving the energy. Therefore, using low-level programming in languages such as C can make your software more sustainable.

Have a look at our language comparison tool, which comprises results of efficiency testings of 27 popular languages used for solving various computational problems. With several exceptions, the general trend is quite simple — the more high-level the language is, the less performant it is, and therefore more energy is consumed.

Disable peripherals when they are not being used

Peripherals such as keyboard and mouse do not consume much energy, but this may not the be case for printers, external hard drives, etc. You need to put them into a sleep state or even disable them completely when they are unused to avoid energy leaks.

Use interfaces with background switching

Various implementations of an interface may be used in one program. You may consider changing them either in response to the change of program state or because of the change of the power supply. This study (2) comprises experimentation results of energy consumption of various different data structures extending same interfaces with different data workloads. The researchers pursue to create an ultimate green data structure, which can change its implementation automatically to ensure the highest possible efficiency. Unfortunately, the researchers are not finished with it, but you can already consider using some of their results and ideas for your software.