Live data from Hacker News

Python consumes 38x more energy than Java

stratoflow.com

61–70 of 142 posts

Re: Python consumes 38x more energy than Java

#62

Earlier quoted context omitted.

I did an excercise some time ago and managed to get two file transfer apps, one in Rust and one in Java, where the performance was effectively the same (in some cases with a slight Java edge!), but the memory consumption was orders of magnitude in favor of Rust. The JVM is a wonder of engineering, and Java is indeed quite fast.

Most reasonable people in the industry understand that Java can be fast, especially in benchmark-oriented code. The problem is that the OOP-first ideology of the language and the coding culture surrounding it is not performance-oriented, especially with modern machines that don't like pointer-chasing. One not very well known fact is that just-in-time compilers have more optimisation-specific info than pure ahead-of-t…

What I noticed is that you have a lot of tools available to tune Java applications, but it was more necessary to rely on them to get to a good spot. In the Rust version, I got a 2x speed improvement by using a rayon thread pool instead of tokio, but the improvements in the Java version were 100x by the end of it.

Re: Python consumes 38x more energy than Java

#63

Amazing. I have seen this list popping up in my LinkedIn feed for more than a year already and it keeps coming back. While any benchmark is of course interesting when considered on its own, the conclusions that people draw from this list tend to be complete nonsense: "Python is bad for the environment", "we should switch to language xxx to combat global warming" etc. First of all, especially for the slower languages…

I think you bring up a good point. Our economic system isn't designed to reward low energy consumption. In fact, GDP and energy usage are very tightly linked. And because we are seeking growth in GDP at a system level, we are doomed to use more energy.

Re: Python consumes 38x more energy than Java

#64

C++ uses 34% more energy than C? I thought C code was generally also valid C++ code and so you really should be able to get the same performance and energy consumption. Very odd.

You can write C in C++ but it won't be idiomatic C++. I've seen plenty of experienced "C++" developers that have no idea what is "shared_ptr".

True partly because shared_ptr is a relatively new language feature; I’ve been locked to a ~decade-old C++ compiler for most of my professional career, and so has everyone I know, just because support for a current compiler across platforms at any given time has been historically so spotty. It seems to be improving at the moment.

> it won’t be idiomatic

I just looked at the first example:

C: https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

C++: https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

The C++ doesn’t use shared_ptr or STL or anything, and isn’t that far from the C code, but it isn’t that close either. I wonder if it’s OMP configuration that’s causing it to be slower, or maybe just instruction cache or something since the C++ is larger.

The results say this one has C++ going 50% slower. I’m a little skeptical it’s the compiler’s or the language’s fault. I’d speculate it might have more to do with how the program is written.

Re: Python consumes 38x more energy than Java

#65
post #37

Earlier quoted context omitted.

Fortran is a beast. People crap on it all the time yet use it often millions of times a day without realizing it.

use in what ? I severely doubt anything I do touches fortran millions times a day unless it's google search that runs on it.

Are you sure you've looked inside all those .dlls and .sos you use every day?

At the end of the day Fortran is compiled and it can just create dynamic libraries which program you use depend on, and you'd never know.

Heck, I wouldn't bet against using me using at least 1 Cobol library once per month, you never know what kind of craziness is going on behind the scenes.

Re: Python consumes 38x more energy than Java

#67

Earlier quoted context omitted.

You seem to be conflating speed and memory usage. A spring boot app will generally be very performant. It will indeed use more memory though.

As a data point I ported a spring boot application to rust and max memory lowered from 200 mb to 9 mb.

I wonder how much you'd save with Micronaut: https://micronaut.io/

> Micronaut is a software framework for the Java virtual machine platform. It is designed to avoid reflection, thus reducing memory consumption and improving start times. Features which would typically be implemented at run-time are instead pre-computed at compile time.

https://en.wikipedia.org/wiki/Micronaut_(framework)

I don't think you'd go down to 9, but something like 20-30 could be doable.

Re: Python consumes 38x more energy than Java

#68

While Java's compiler or JIT is probably one of the most optimized softwares in existence, how do we measure, what overhead the language nudges the programmers to build? I am thinking of AbstractProviderFactoryProxy and similar. Or that for a very long time it forced you (or still does to a degree) to put everything into classes, breeding 1 or 2 generations of programmers, who see a noun and jump to making a class an…

Please explain how "AbstractProviderFactoryProxy" is related to the language. I have taken over as lead for a Python project and what I see all the Java problems people used to make fun of (none have worked in Java before) and worse. On top, everything has an interface starting with "I", C# style. Methods in entities, service classes are instantiated with state etc. And side-effects are all over the place. If you are…

> Please explain how "AbstractProviderFactoryProxy" is related to the language.

The language Java did, until some time ago, not allow you to pass functions as arguments. You had to make an anonymous inner class for example, satisfying some interface. Many design patterns are very much oriented towards a language like Java, which does/did not allow for higher order functions.

Take the visitor pattern for example. It will get you a "Visitor" in your class name implementing a visitor. How would it work in other languages, which provide higher order functions or always did so? Well, you would simply write a function and depending on whether your language has static types, annotate its types for arguments and return value. You would then pass this function in as an argument, whose name can be "visitor".

Take a factory pattern as an example. How would it work? Well, a factory can be expressed using a function, that returns another function. It takes the arguments, that specify/narrow down how the returned function works. In Java it would become a Factory class instead. Instead of using a simple function, one needs (needed?) to build a whole class around that, because one could not return a function. So one would build that class and then make it return an object instead, which of course again must be derived from some class ...

Just 2 examples that quickly come to mind.

> I have taken over as lead for a Python project and what I see all the Java problems people used to make fun of (none have worked in Java before) and worse.

It is certainly true, that people also write shit code in Python. I have seen very popular libraries, which wrap REST APIs in objects. It is silly, because objects are meant to have some lifetime in which they communicate with each other and possibly change their state. There is no changing state though. Everything is a response from the REST API, which by the definition of REST should transfer the representative state in its responses. I don't want any in between stored state. I want the state that the API gives me. It is very much a more functional view on things. But Python programmers will go "make classes!" nevertheless. Because noun. Because not thinking about whether they really need a class. Because thinking that one approach fits it all and the only approaches they learned were procedural at the beginning of their learning and then OOP, which is complex enough to take years to learn properly, so that is where they stopped.

However, Python always (for a very long time?) has allowed you to pass procedures as arguments and as such does not encourage "AbstractProviderFactoryProxy" as much as Java does. Still, sometimes former Java developers try their hand at some Python code ...

> If you are writing modern Java syntax, there is little that is more stable and readable than good modern Java syntax.

Modern Java certainly has improved. But there is a lot of relearning to be done for those generations of Java programmers, to get rid of the "every noun a class" mentality.

Re: Python consumes 38x more energy than Java

#70
post #67

Earlier quoted context omitted.

As a data point I ported a spring boot application to rust and max memory lowered from 200 mb to 9 mb.

I wonder how much you'd save with Micronaut: https://micronaut.io/ > Micronaut is a software framework for the Java virtual machine platform. It is designed to avoid reflection, thus reducing memory consumption and improving start times. Features which would typically be implemented at run-time are instead pre-computed at compile time. https://en.wikipedia.org/wiki/Micronaut_(framework) I don't think you'd go down to…

Actually I ported it to Micronaut too and compiled it to native code. It's difficult to know exactly what the minimum amount of memory that a java application could run with during normal load, but I'd estimate that it was around 150 mb instead of 200 which was disappointing, 128 mb got intermittent OOMs. But the code was nicer than spring boot (or rust).
Post reply on HN