Catch up on stories from the past week (and beyond) at the Slashdot story archive

 



Forgot your password?
typodupeerror
×
Cloud Programming Earth Power

Is It More Energy-Efficient to Program in Rust? (amazon.com) 243

A recent post on the AWS Open Source blog announced that AWS "is investing in the sustainability of Rust, a language we believe should be used to build sustainable and secure solutions."

It was written by the chair of the Rust foundation (and leader of AWS's Rust team) with a Principal Engineer at AWS, and reminds us that Rust "combines the performance and resource efficiency of systems programming languages like C with the memory safety of languages like Java."

But there's another reason they're promoting Rust: Worldwide, data centers consume about 200 terawatt hours per year. That's roughly 1% of all energy consumed on our planet... [C]loud and hyperscale data centers have been implementing huge energy efficiency improvements, and the migration to that cloud infrastructure has been keeping the total energy use of data centers in balance despite massive growth in storage and compute for more than a decade... [I]s the status quo good enough? Is keeping data center energy use to 1% of worldwide energy consumption adequate..? [Will] innovations in energy efficiency continue to keep pace with growth in storage and compute in the future? Given the explosion we know is coming in autonomous drones, delivery robots, and vehicles, and the incredible amount of data consumption, processing, and machine learning training and inference required to support those technologies, it seems unlikely that energy efficiency innovations will be able to keep pace with demand...

[J]ust like security, sustainability is a shared responsibility. AWS customers are responsible for energy efficient choices in storage policies, software design, and compute utilization, while AWS owns efficiencies in hardware, utilization features, and cooling systems.... In the same way that operational excellence, security, and reliability have been principles of traditional software design, sustainability must be a principle in modern software design. That's why AWS announced a sixth pillar for sustainability to the AWS Well-Architected Framework. What that looks like in practice is choices like relaxing service-level agreements for non-critical functions and prioritizing resource use efficiency. We can take advantage of virtualization and allow for longer device upgrade cycles. We can leverage caching and longer times-to-live whenever possible. We can classify our data and implement automated lifecycle policies that delete data as soon as possible. When we choose algorithms for cryptography and compression, we can include efficiency in our decision criteria.

Last, but not least, we can choose to implement our software in energy efficient programming languages.

There was a really interesting study a few years ago that looked at the correlation between energy consumption, performance, and memory use.... What the study did is implement 10 benchmark problems in 27 different programming languages and measure execution time, energy consumption, and peak memory use. C and Rust significantly outperformed other languages in energy efficiency. In fact, they were roughly 50% more efficient than Java and 98% more efficient than Python. It's not a surprise that C and Rust are more efficient than other languages. What is shocking is the magnitude of the difference. Broad adoption of C and Rust could reduce energy consumption of compute by 50% — even with a conservative estimate....

No one developer, service, or corporation can deliver substantial impact on sustainability. Adoption of Rust is like recycling; it only has impact if we all participate. To achieve broad adoption, we are going to have to grow the developer community.

That "interesting study" cited also found that both C and Rust execute faster than other programming languages, the blog post points out, so "when you choose to implement your software in Rust for the sustainability and security benefits, you also get the optimized performance of C."

And the post also notes Linus Torvalds' recent acknowledgement that while he really loves C, it can be like juggling chainsaws, with easily-overlooked and "not always logical" type interactions. (Torvalds then went on to call Rust "the first language I saw which looked like this might actually be a solution.")

The Rust Foundation is a non-profit partnership between Amazon Web Services (AWS), Google, Huawei, Microsoft, and Mozilla.
This discussion has been archived. No new comments can be posted.

Is It More Energy-Efficient to Program in Rust?

Comments Filter:
  • by eneville ( 745111 ) on Sunday February 20, 2022 @07:38AM (#62285275) Homepage

    Yes... but that's not the only reason. There's the ecosystem effect too, if it is less likely to have bugs due to the language design, then there's less overhead (transit, distro patching/maintenance etc).

    • by Kisai ( 213879 )

      The thing is,

      a) Rust, horrible brand name, I wish it was called something that didn't sound like unwanted or a side effect.
      b) C does everything, and you should be using C if your project needs to be speed-oriented.

      If Rust is even 99% of C, it's still not C, and people will pick it apart for that.

      That said, Java, Python, PHP, and Javascript (as in browsers and node.js) waste a lot of energy because their purpose is different. They are different tools.

      If we want to jump on the energy efficiency argument, we s

  • No. (Score:5, Interesting)

    by The Evil Atheist ( 2484676 ) on Sunday February 20, 2022 @07:59AM (#62285293)
    It's more energy-efficient to program in COMPILED LANGUAGES compiled by OPTIMIZING COMPILERS.

    There's nothing special about Rust that makes it energy-efficient. It's all to do with the fact that it does not need a translation layer to execute, just like every other compiled language.

    And before any pedants come out, it's obvious from the context that I'm talking about languages compiled to the native machine for the machine it runs on, not compiling to bytecode of some sort.
    • Obviously the idea is that Rust lets you have the advantages of compiled languages without giving up safeties usually offered by interpreted languages. So if you don't want to "juggle chainsaws", as Torvalds put it, you don't have to choose a language with an inefficient runtime environment. You can choose Rust.
      • Re:No. (Score:4, Interesting)

        by The Evil Atheist ( 2484676 ) on Sunday February 20, 2022 @09:12AM (#62285417)
        Rust is not the only compiled language to offer safety, and all the Rust CVEs shows that it does not actually escape the problems of other compiled languages.
      • Re:No. (Score:4, Insightful)

        by Joce640k ( 829181 ) on Sunday February 20, 2022 @09:31AM (#62285453) Homepage

        Obviously the idea is that Rust lets you have the advantages of compiled languages without giving up safeties usually offered by interpreted languages. So if you don't want to "juggle chainsaws", as Torvalds put it, you don't have to choose a language with an inefficient runtime environment. You can choose Rust.

        So does C++ if you use std::string, std::vector, etc., for storing data.

        STL data storage means memory is freed automatically and buffer overflows are eliminated.

    • And before any pedants come out, it's obvious from the context that I'm talking about languages compiled to the native machine for the machine it runs on

      You can compile Java to native code, yet that sill won't magically make Java any more efficient if for example you need to deal with unsigned word-sized numbers efficiently, like you do in cryptography and some other types of programs.

      • You can compile Java to native code

        You can't do that with the default tools but yes, it is possible.

        yet that sill won't magically make Java any more efficient if for example you need to deal with unsigned word-sized numbers efficiently, like you do in cryptography and some other types of programs.

        How did you miss the "compiled by OPTIMIZING COMPILERS" part which completely sinks your argument? Seriously, it was on the first line.

        • Here I was not even considering running Java through a non-optimizing compiler, be it a non-optimizing JIT compiler or a non-optimizing AOT compiler, so I'm not sure why this distinction would be relevant here. Of course we're talking about optimizing language implementations here. Why would you use any other these days? (Outside perhaps of some very restricted device profiles such as embedded applications, smart cards etc.)
          • In that case, compiling to native code is more energy efficient than running bytecode because it doesn't depend on a dynamic recompiler AKA JIT to transform it into native code, a process which expends cycles.

            It really doesn't get any more basic than that.

            • For long-running processes such as the ones in data centers, these are asymptotically indistinguishable. The compilation takes a fixed amount of time whereas execution is essentially unbounded. The ratio of a fixed number divided by an unbounded number converges to zero.
              • For long-running processes such as the ones in data centers, these are asymptotically indistinguishable.

                It seems you are referring to the use of caching in the dynamic recompiler which results in increased memory use and is limited supporting runtime environments.

                However, the point was abstract: scripts and bytecode are intrinsically more energy inefficient than native code because they must be translated to native code. QED.

                • It seems you are referring to the use of caching in the dynamic recompiler which results in increased memory use and is limited supporting runtime environments.

                  No, I'm not. I'm simply referring to the fact that compilation takes a bounded amount of time whereas execution of server processes takes an unbounded amount of time, and the limit of their ratio is zero. That has nothing to with caching, recompiling, memory use or anything like that.

                  scripts and bytecode are intrinsically more energy inefficient than native code because they must be translated to native code. QED.

                  They don't really *have* to be translated into native code, depending on the execution environment, but if they aren't translated, they are indeed much more inefficient (for example like MS Blazor's current use of a WASM intepr

        • Comment removed based on user account deletion
          • It's compiled to machine code immediately before execution and that machine code typically exists until the instance of the application is terminated.

            I'm fully aware of the dynamic recompilation and caching that is employed by JRE.

            The fact that bytecode must be translated to native code means that addition energy is being expended compared to starting off as native code. QED.

          • I don't think there's anything in Java that cannot be achieved in Go, it has an identical memory model

            Well, almost. Go allows for interior pointers to components of structs. That on one hand makes GC somewhat more complicated, but on the other hand saves quite a bit of working memory.

    • Are you somehow trying to imply that my Perl based Python interpreter is somehow energy inefficient?! Well I never!

      Since this website only has silly insults, I won't be pointing my glorious Grail browser [wikipedia.org] toward it!

  • Data centers use 1% of world energy and Rust is 50% more energy efficient than Java?

    Nah, throw more hardware at the problem. Build a couple more wind generators.

    • I think this is the general point, but it also goes for the laptops/phones that people use. Poor software is driving hardware sales at the moment and contributing to ewaste. Imagine if phones/laptops didn't need such rapid hardware refreshes.

    • I dunno. Java is a hot mess. Rust is a big cloud edge language now which makes me feel compelled to accept some of the hype. But I haven't personally pulled the trigger on it yet. Not saying I won't, just saying not yet.
      • Go for it! I'm a big Rust fan and have `been using it for everything that I would have done in C++. The compiler error notifications and indeed the whole Rust ecosystem are just excellent. Whenever I complete a Rust project, I have this great feeling that I've produced something very solid.
  • "Interpreted languages" or "bytecode languages" traditionally lag behind native implementations by roughly a factor of 10, far more than the 50% cited here.

    My guess is that practical computing has changed. In the olden days RAM could easily keep up with the CPU, so much so that some CPU architectures actually kept their registers in RAM. Modern processors however are much faster than RAM. So if you process some data that is not yet in the cache your CPU will have to wait quite some time for the data to arri

    • by pz ( 113803 )

      In the olden days RAM could easily keep up with the CPU, so much so that some CPU architectures actually kept their registers in RAM.

      That hasn't been true for ... at least the not-quite-50 years that I've been programming, and probably longer. The first single-chip CPU I wrote code for was the 6800 (not 68000) and it had on-chip registes that were gobs faster than RAM. The then-contemporary Z-80, 8080, and 6502 also had on-chip registers.

      • Some 68k machines were the last machines I'm familiar with where it was more or less true, because they could use SRAM. I'm talking about select Amiga computers here, specifically. I believe you can add SRAM to 1000, 500, 2000, 600, and 1200 at least. Registers are still faster than having to access memory, but SRAM is wildly faster than DRAM.

    • there are plausible reasons why the ratio has shifted from 10x to 2x.

      JIT compilation.

    • I wrote tiny bytecode interpreters for primitive UI functions in an 8080 assembly environment, both for coding convenience and to conserve scarce memory. There was no cache, so every instruction required a memory read plus some number of internal clock cycles. The speed penalty was around a factor of 30 if the interpreter was general purpose (like Pascal bytecode) with a simulated register or stack model, but less for UI or electromechanical simple state machine and string formatting interpreters. Cache,

  • by ptaff ( 165113 ) on Sunday February 20, 2022 @08:16AM (#62285315) Homepage

    Yeah, closer to the metal, better CPU utilization, captain Obvious.

    But as good little Rust shills, let's avoid mentioning Rust's unstable ABI, that makes shared libraries a practical impossibility.

    Static linking wastes disk space and memory, meaning beefier hardware is required.

    And it also means the tiniest security problem in a library involves updating all programs using that library. Hope your recompile/reinstall cycle uses zero energy!

    Please don't invoke the bullshit argument "the number of vulnerabilities is severely decreased, because Rust language itself makes code secure"; sure, it may help, but for such a niche language, I find the number of Rust-related CVEs [mitre.org] really impressive.

    • There's a reason these editors like rust so much. It's usually much more "loved" on stackoverflow than actually used.

      Meaning the wannabes like drooling all over it. And... that's about it. They're not the ones that get around to using it and learning in minute detail what works and what doesn't work in and with that language and its "ecosystem".

      As flawed as C is, it works, and works pretty well. We by and large know what you can and cannot, should and should not do with it. rust? If I had a task that was

      • The thing folk almost certainly like but dont admit thats what it is, is the included libraries.

        People leave C/C++ in waves.

        These waves can be labeled. The Java wave. The .NET wave. The Python Wave.

        We are now on the Rust wave. Like all the other fucking waves, the programmers moving from one language to another, all of the waves are the same. They are moving to something they could have gotten 30 years ago but at the fucking time they were badmouthing the obvious destination.

        1980's BASIC:
        let x = 1
        • It seems like there are some recent developments in computer science that have passed you by. But that's understandable, type inference is only from 1958 after all, that's like yesterday.

        • People leave C/C++ in waves. These waves can be labeled. The Java wave. The .NET wave. The Python Wave.

          If you give people more options, of course some of them will use the new options.

          1980's BASIC: let x = 1 2020's C-like: var x = 1

          Well at least the "2020's C-like" has structures now. 1980's BASIC as a rule didn't. (At least not any of the dialects I had access to back then...)

    • Unstable ABI is relevant only for Rust and means that you need the same compiler version to produce binaries. I don't see how is that an issue. Nothing prevents you from making a shared library in Rust and export symbols with C ABI.
  • by devslash0 ( 4203435 ) on Sunday February 20, 2022 @08:22AM (#62285323)

    The efficiency of the code does. Nothing's going to help if you let a noob write a dozen nested loops instead of a proper algorithm to solve a problem.

  • The more mistakes you make, and the more serious they are, the more you learn and become a better programmer.

    • There may be some survival bias embedded in that conclusion...

      • Its easy for the least capable to claim that the thing they couldnt get over was unfair, that those that did get over it are biased.

        So easy, in fact... that its predictable. You are predictable.
      • by hawk ( 1151 )

        Just because Lefty isn't saying anything, and No-Head *can't* say anything, you reach this conclusion? :)

        hawk

    • C as trillion dollar economic damage training wheels for system programmers seems a poor investment to me.

    • One of the great things about Rust is that it has made me a better C++ programmer, because when I started programming in Rust, I made a lot of mistakes. However, the Rust compiler caught those mistakes (and told me how to avoid them). The mistakes didn't make it into a running application, like they would have if I had been programming in C++.

      It really made me question things that I had never considered when programming C++ with a C mindset. I've come to realize that I really need to be more careful wit

  • Someone could generate a lot of electricity from all the hot air being blown around trying to sell Rust.
  • by ffkom ( 3519199 ) on Sunday February 20, 2022 @08:46AM (#62285371)
    As if the a programming language decided what energy is spoiled for... if you save a little here, people will add more abstraction layers and "bling bling" elsewhere to the software. And use less efficient algorithms and data structures because they cannot be bothered to contemplate their efficiency.

    And if, after all, any energy savings are left, crypto-miners will gladly use them up.
  • The chair of the Rust Foundation released a study today indicating that programming in compiled languages is more efficient that programming in interpreted languages. In other news, the VP of Marketing for Nestle' Waters released a study indicating that drinking water is better for the body than drinking bleach... Details at 11.

  • by jd ( 1658 ) <imipakNO@SPAMyahoo.com> on Sunday February 20, 2022 @09:34AM (#62285461) Homepage Journal

    To me, all languages are syntactic sugar on top of an abstract description.

    True, some things you can do in one language can't be done in another, but then not all sugar is interchangeable either.

    When it comes to energy efficiency, I can believe Rust does a decent job. But there are tens, if not hundreds, of thousands of computer languages and I sincerely doubt this is a metric many of them have been weighed against.

    Even if you're going to use C as the universal representative, you need to be careful.

    Let's say a worker thread in C runs 10x as fast but generates 10x as much heat per second as a similar thread in language Blah, then the total energy efficiency of C and Blah for that task would be the same. In other words, it's total energy that matters.

    But you can always refactor tasks. Make them more efficient, up to the level the language permits.

    So the next obvious question is, how far does the language let you go? Does an ideal Rust solution optimised for energy beat an ideal C solution optimised for energy?

    (Remember, there isn't an option for this in the Gnu C compiler.)

    And how do you know when you've enough cases to be representative? What are we using to gauge the p value?

    So I've absolutely no issue with anyone espousing a given solution. That's healthy.

    Boasting about a metric by comparing it with popular alternatives only tells me that democracy doesn't work in finding good engineering solutions, but that's obvious.

    Having a reasonably comprehensive table of languages and scenarios that allows you to compare any ordered pair of (language, scenario) to a given metric would be wonderful but nothing like it exists, nothing like it is likely to exist and we shouldn't pretend that it does.

    Until you can tell me how Rust compares to Ada, Mars D, Eiffel, Erlang, Haskell, Occam Pi and MUMPS, in addition to ISO C, C++ and Java, all three of which are very similar, then you've not told me much.

    And if you're comparing purely out of the box, so not including third party libraries, you've said even less because its apples to oranges.

    (If I want to compare prefab houses to alternatives, I don't compare them to a pile of rocks, done wooden planks and a box of nails, I compare them to stone houses and half timber houses. Then it is like with like.)

    But, again, there's a lot of libraries out there. Do we use GLibc or New Lib? Do we use the builtin malloc, mimalloc, tcmalloc or Hoard? Or even a debugger malloc?

    (If we're trying to match features to get the closest apples to apples we can, this matters.)

    And then there's expertise to consider. Just as it takes different skills to build a broch versus the prefabricated parts of a mobile home, how do we make sure we're comparing two equivalent programmers, one skilled in Rust and another in C?

    A comparison of existing code won't help. McLaren builds very fast, powerful, fuel-hungry Formula 1 cars, comparing them to a hybrid on fuel efficiency is stupid.

    But those same engineers build a car capable of 100mpg at 100mph carrying two adults and two children using the same tech as went into F1.

    So we have to compare what tech will do when built for the same purpose not opposing purposes.

    It is not a simple comparison.

  • If you're worried about energy use and environmental impact, I'd ask what all this code is doing in the first place, and is it "necessary"? More cat videos? Another cryptocurrency? Duplicate Slashdot articles?

    My friend proudly shows me his doorbell camera feed--this phone feed wastes juice every time he gets a delivered package. "It's for security." "You know I can break in to your house while wearing a mask, and the doorbell itself won't prevent anything?"

    People, particularly their over-population
    • "You know I can break in to your house while wearing a mask, and the doorbell itself won't prevent anything?"

      No, no. You're completely missing the purpose of the modern doorbell camera feed, which is to provide for generalized surveillance at various levels of governance, while at the same time providing a mineable data stream for commercial operations.

      Both the government and those commercial operations are quite certain that the money spent by those doorbell owners is well invested in their interests.

      "You

  • If a programming language targets a specific subset of programming challenges, it's relatively easy to build an efficient platform. If a language is designed to support a full set of programming problems, including UIs, it becomes much more difficult.

    So as much as it would be nice to take advantage of Rust's good performance and reliability, it's usefulness is limited because it doesn't cover apps that need a UI.

    Yes, I know Rust can target WebAssembly and Electron and use HTML as a front end. But WebAssembl

    • by Tailhook ( 98486 )

      Microsoft actively supports windows-rs [github.com]. With this you can build native UI application for Windows. This has the same performance as anything you might code in C/C++ on Windows; all you're doing here is calling the same ddls that a C/C++ program would call.

      The well supported gtk-rs system provides a portable native GUI API. Here [gtk-rs.org] is the the official book on GTK for Rust. Again, you're calling the same native objects so the same performance will emerge.

  • I'm a C programmer, but I recognize that it takes longer for a C program to be written and debugged than a Python or Java program. So if the end result can indeed be more power efficient, how much extra time (and computer power) has been spent developing and debugging it ?
    • Debugging it once compared to running it millions of times on a thousand servers? I think the development effort might get lost in the noise in terms of power efficiency. The energy aside, the engineering process is a good chunk of the software's cost in dollars and cents.

  • by Qbertino ( 265505 ) <moiraNO@SPAMmodparlor.com> on Sunday February 20, 2022 @10:26AM (#62285563)

    If you know what you're doing and/or are programming embedded stuff, Rust is a very good candidate for energy efficiency. I doubt any part of the Mars Rovers is programmed in Python or Perl.

    If however time to market is your constraint and the product is your typical web based application, then programming in Rust is likely to be so inefficient that the lifecycle uses more energy than, let's say, PHP.

    Point in case: If I need to babysit and orchestrate a container setup just to keep something running, LAMP will be an order of magnitude more energy efficient. And efficient in others ways too.

  • How much energy is used by developers? Unless you are developing at extreme scale, the energy used to develop the software is going to dwarf the costs of running it.

  • In a single tournament, an elite chess player burns 6000 calories. The amount of mental activity in a top performing human being can be staggering. Now how does Rust, Java, C, C++, Python and Go compare in terms of the human energy necessary to accomplish basic programming tasks?

  • If you compare a computationally expensive operation, like matrix inversion, by doing naive implementations in both c and python, of course c or rust is going to be 100x better. But in any production code, operations like that are going to be implemented in the same highly optimized libraries for all of those languages, such as blas.

    The trade-off is really performance and reliability versus speed of implementation. It makes the most sense to write the majority of an application in a high-level language su

  • Ok, I have gray hair, but: the first computer I owned was at least 20,000 times slower than current systems, on top of which it did not have built in floating-point or any of the other fancy instructions. It worked just fine. Now we have nicer GUIs, and some nice things happening in the background, but it remains a mystery: where is that 20,000+ performance gain?

    The answer isn't in the programming languages. The answer lies in frameworks. Joe and Jane average programmer doesn't write his own code any more

  • Java is most energy efficient language right now - b/c of 20+ years of coal mining that produced current state of open source libraries. Start with Rust and you have to reinvent all of it from scratch.
  • I routinely code my Python to be within 2x-3x speed of native C/C++/Rust/Go implementations. The memory footprint is always larger, but even so the 50x efficiency difference mentioned above must be bogus, unless the Python code was "stupid", intentionally avoiding any and all optimizations.

    For comparisons against static languages, the dynamic nature of Python is NOT NEEDED, and there are multiple ways to bypass that burden, which greatly increases overall efficiency (speed, memory, power).

    First, code to "l

  • Energy efficient? All I care about is my own energy -- the effort to write a correct, efficient program -- and that's the only thing you should care about, too.

You are always doing something marginal when the boss drops by your desk.

Working...