Green-Software-Foundation / patterns

An online open-source database of software patterns reviewed and curated by the Green Software Foundation across a wide range of categories.
https://patterns.greensoftware.foundation/
Other
76 stars 29 forks source link

Using Complied Languages rather than Interpreted Languages #132

Open aoifefitton opened 1 year ago

aoifefitton commented 1 year ago

Describe the pattern you'd like to propose Compiled languages “tend to be” the most energy-efficient - see paper linked in reference section.

Actions:

Describe specific emission impact from this pattern Regarding SCI = ((E I) M) per R, E will decline with use of the likes of C/Cpp rather than Python.

More stats: https://devblogs.microsoft.com/sustainable-software/language-impact-on-ui-apps/

References to this pattern Compiled languages “tend to be” the most energy-efficient: See table 3: https://greenlab.di.uminho.pt/wp-content/uploads/2017/10/sleFinal.pdf?utm_source=thenewstack&utm_medium=website&utm_campaign=platform

https://thenewstack.io/which-programming-languages-use-the-least-electricity/

Additional context C is low level in the sense that it enables direct manipulation of the computer hardware (at least as direct as the OS will allow). The most common implementations of Python, Java, etc. are at least one step further removed from the hardware because they run in a VM. If you want to manipulate the hardware from Python you'll have write an extension to the Python VM, usually in C or C++. There's no virtual machine interpreting C executable code. It's compiled into machine instructions, specific to a particular CPU, that are linked together and run on your hardware

markus-gsf-seidl commented 1 year ago

I'll convert this, but I'm torn. This topic is very complex and I think we should touch it very carefully. Maybe the best option is to have a project that does actively benchmark this. The greenlab link seems to provide a GSF compatible source, but the last work done is from many years ago.

@dubrie Is there a category for this? I would throw it into cloud, but maybe there could be a more general category

dubrie commented 1 year ago

@markus-ntt-seidl I think cloud is OK as a category for now (can re-sort as more patterns get filed) but we do have a tag for programming-language already so let's make sure that tag is in there.

s-geiger-si commented 10 months ago

We would love shift the focus of the pattern towards what is the most energy efficient solution for a given problem.

Most developers would not write a REST API in a low-level language like C (although maybe it could be done). On the other hand, if we look at Python, Javascript (Node) and Java, then all three languages are perfectly suitable for a RESTful microservices. but according to the links below they have a hugely different energy consumption, so the choice then should lean to Java over python (as an example).

We suggest to extend the considerations section with the following items:

markus-gsf-seidl commented 9 months ago

Maybe we step this down a notch or two and suggest that the implementers should consider performance optimising hot-spots of their code in different directions, instead of advising them to choose this or that.

Try to use:

Personally I still think this whole pattern will be a can-of-worms: Comparisons are very academic, good algorithms are faster even in slower languages and programming paradigms are very important (to a limit given by each domain). There are so many real world things to consider to master performance and green software (are these even synonyms?) I remember Twitter moving to Async IO Java, since it was more efficient than doing this DIY in C. RESTful APIs can be written in C, but it may not be realistic to do so.