Live data from Hacker News

Which Programming Languages Use the Least Electricity? (2018)

thenewstack.io

141–150 of 267 posts

Re: Which Programming Languages Use the Least Electricity? (2018)

#141
post #28

Earlier quoted context omitted.

>typical TypeScript programs are faster than typical JavaScript programs Person who works on js engines here :) You would think this is the case, but in actuality, js and ts are about on par in performance (assuming similarly written code). This is in fact due to the fact engines optimize for idiomatic js patterns, not idiomatic typescript patterns. often these will align, but in some cases (usually revolving around…

Any articles/resources on writing high-performance JS that you would recommend? I don't use JS for work, but just for random fun stuff. So just curious to learn more about it.

Check out gl-matrix.js, that’s one designed for being fast. It’s a simple math library, but the main way it achieves fast is by not allocating memory.

After having worked on JS for some large web apps that need good graphics performance, the two rules of thumb in my head for making JS fast are: 1- avoid dynamic memory allocation, and 2- avoid using the functional primitives like map.

The first one is more or less true in all languages, memory allocation always costs a lot, and if you can pre-allocate memory and/or re-use memory along the way, the code will run faster. This means paying attention to what things in JavaScript will allocate memory under the hood, use of dicts, use of 3rd party library and framework functions, etc.

The second one is a bummer; I love using the functional primitives. But map is slower than a for loop, all else being equal. It has gotten relatively faster over time. I mostly use functional everywhere, and only resort to for loops in performance critical code.

Re: Which Programming Languages Use the Least Electricity? (2018)

#142
post #18

Earlier quoted context omitted.

How does less dev time save energy “somewhere else in the world”? Google & AWS pay money to develop & acquire technologies that save energy because of their scale. The energy used in dev is scratch compared to the energy used to run programs at scale. Google, for example, has a PHP compiler that makes all PHP web pages execute in a fraction of the energy usage of running the PHP interpreter.

Not everyone works for FAANG. Energy usage doesn’t even come up at most small shops. Cloud hosting costs might, but only if they are really out of whack.

You might be misunderstanding. AWS and Google and a few others are hosting everyone’s code, all the big shops and all the small shops and everyone in between. They do things to optimize everybody’s code, because it saves literally millions on their power bills.

Re: Which Programming Languages Use the Least Electricity? (2018)

#143
Now, seriously: C and the boogieman of managing your own memory is a myth. Anything you want from another language can be built up from C, and be in your direct source code control working in C. Far too much propaganda is written telling programmers perfectly capable of the gains from working in C that they should be afraid of working with their own memory allocations. As if being organized is impossible.

Re: Which Programming Languages Use the Least Electricity? (2018)

#144
But at the same time, when manipulating strings with regular expression, three of the five most energy-efficient languages turn out to be interpreted languages (TypeScript, JavaScript, and PHP), “although they tend to be not very energy efficient in other scenarios.”

I believe that's because they're all using a regular expression library which is probably written in C/C++, maybe even with some pieces in optimised Asm, so none of the actual RE-work is being done in the interpreted language itself. If you wrote actual RE processing in the interpreted language and let the interpreter interpret/JIT it, I bet they would be as (in)efficient as the "other scenarios" where the "heavy lifting" is running through the interpreter.

Re: Which Programming Languages Use the Least Electricity? (2018)

#145
post #121

Earlier quoted context omitted.

How do you get the 11 years figure? What is your idea of a drastic reduction? How will you measure it? And should all countries observe it equally?

Fortunately there are really extensive online resources you can consult for details! For example the United Nations Intergovernmental Panel on Climate Change.[1] [1] https://en.wikipedia.org/wiki/Intergovernmental_Panel_on_Cli...

The United Nations has something like 30 different climate models. Also no one can forecast next month’s weather accurately, much less the weather from 12 years from now. Or do you know of a more accurate forecasting model? Such a model would be extraordinarily useful in agriculture and emergency management, for example.

Re: Which Programming Languages Use the Least Electricity? (2018)

#146

The code size metric was pretty interesting to me. I would have imagined that functional programming languages should lead to the most succinct code. But I was surprised to see Haskell in the middle, and Go at the top there! Functional languages are right in the middle for all 3 metrics.

Unfortunately there are no APL/array languages there, they are notorious for being succinct! It's not a stretch to say "lines of code" in most other languages would be close to "characters of code" in APL. It'd be interesting to compare it using the other metrics too.

Re: Which Programming Languages Use the Least Electricity? (2018)

#147
post #91

Couple points (I've worked on app servers): 1- This is exactly how we should all be thinking about server engineering moving forward, as we aim to drastically reduce carbon footprint within 11 years. Efficiencies at the language level are one of biggest bangs for buck here. Just by redeploying, you can reduce energy consumption by perhaps double digits. Imagine how hard that is to do at the hardware or energy farm le…

I've spent the past several years programming w/ Swift, but the performance is a little concerning. Maybe the switch in Swift 5 to utf-8 backed Strings improves the performance?

I think Rust w/ macros like you see in Rocket (https://rocket.rs/) looks promising. I haven't used it, but the guarantees, simplicity, and performance (possibilities - it doesn't use async yet) are really interesting.

Re: Which Programming Languages Use the Least Electricity? (2018)

#148
post #18

Not sure how serious they think this is, and how much is this rather a joke. If it's not a joke, they clearly not see the big picture. For example if you can write a software in a higher level language in a fraction of the time which will spare energy somewhere else in the world, it will use less electricity overall.

How does less dev time save energy “somewhere else in the world”? Google & AWS pay money to develop & acquire technologies that save energy because of their scale. The energy used in dev is scratch compared to the energy used to run programs at scale. Google, for example, has a PHP compiler that makes all PHP web pages execute in a fraction of the energy usage of running the PHP interpreter.

...Google has a PHP compiler? Don't you mean Hack/HHVM by FB?

Re: Which Programming Languages Use the Least Electricity? (2018)

#149
post #142

Earlier quoted context omitted.

Not everyone works for FAANG. Energy usage doesn’t even come up at most small shops. Cloud hosting costs might, but only if they are really out of whack.

You might be misunderstanding. AWS and Google and a few others are hosting everyone’s code, all the big shops and all the small shops and everyone in between. They do things to optimize everybody’s code, because it saves literally millions on their power bills.

Yes I can see that. As a small shop developer, I will make my choice of language based on programmer convenience rather than energy usage. I have never heard any developer talk about "kilowatts" when choosing tech (outside of bitcoin mining perhaps).

Re: Which Programming Languages Use the Least Electricity? (2018)

#150

This study is a bit silly, I had to check whether it was an April Fool's joke. The chipset running the instructions is going to have a far higher impact on energy usage than the language compiling those instructions. For instance, switching to ASICs or even FPGAs that are optimized to handle certain types of computations. Just look at datacenters or mobile devices. Sure, optimizations are made to runtime environments…

To the naysayers: these languages are either compiled, or will be JIT'ed at runtime. What they will be compiled to will be chip specific binaries-- x86, ARM, whatever. The energy usage will be markedly different depending on which chip architecture is chosen, and will no doubt be inconsistent between different architectures and languages. Or to put it another way. Why do you think mobile devices almost exclusively us…

With regard to datacenter operators, I would argue that a simpler answer to that observation is that they are investing heavily in the are in which they can actually effect change. That is, they can swap in-and-out their hardware, but language of choice is largely up to their customers - the dev. They can advocate and champion a particular language, but really enforcing it in any meaningful way is narrow casting their own user base.
Post reply on HN