Can Rust save the planet? Why and why not • The Register


Re: Invent Here, in an out-of-print AWS Re: invented in Las Vegas, Rust Foundation president Shane Miller and Tokio project manager Carl Lerche made a case for using Rust to minimize environmental impact, though its steep learning curve makes it difficult.

Miller is also a senior director of engineering for AWS and Lerche a senior engineer at the cloud giant.

How can Rust save the planet? The answer is that more efficient code requires fewer resources to function, which means less power consumption in data centers and also the environmental impact of manufacturing IT equipment and shipping it around the world. whole.

Shane Miller and Carl Lerche on Rust’s Efficiency and Safety at This Year’s AWS Re: Invent Show in Las Vegas

“Data centers consume… 1% of all the world’s energy,” Miller said, adding that the total energy consumed had changed little in ten years, thanks to advancements in technology and the trend in the cloud. reduce the proportion of unused resources.

The second part of the argument is that Rust is among the most efficient programming languages. The source cited for this is an article from 2017 [PDF] which measured the performance, memory usage, and power efficiency of 27 programming languages, and ranked C as the most efficient, but Rust just behind with just three percent more power consumption. Java uses almost double the energy, C # more than three times, and Python more than 75 times as much, according to the study.

Languages ​​ranked by energy efficiency, according to a 2017 research project

Languages ​​ranked by energy efficiency, according to a 2017 research project

It’s an AWS conference after all

Research is problematic, as several observed in Monday’s session, not for carelessness, but because languages ​​have many implementations and compilers, some of which are more efficient than others. It’s also strange to find TypeScript 10 times less efficient than JavaScript, given that it compiles to JavaScript and similar code can be written in both.

Still, this is not so important since the effectiveness of Rust as a system language is beyond doubt, and Miller and Lerche did not rely solely on this research. Miller also referred to case studies of Discord and Tenable which showed huge efficiency gains.

In the case of Tenable, a JavaScript component was rewritten in Rust and achieved a 50% improvement in latency, a 75% reduction in CPU usage, and a 95% reduction in memory usage. . “It’s kinda crazy,” Miller said. “These are substantial savings, not just in infrastructure, it translates into energy savings.”

Waste collection languages ​​are inherently less efficient, Lerche said. Garbage collection is a common way to automate memory management and works by identifying objects that are out of range and freeing their memory.

“The garbage collector is going to have to interrupt the process to make the garbage collector pass. And when he’s on a break… the service is no longer able to respond to requests, ”he said. This means that languages ​​like Java, C #, and JavaScript can never be as efficient and performant as C and Rust.

Why not just use C and C ++? The reason is security and memory related bugs, Lerche said, citing research that “70% of all high-severity security vulnerabilities in C and C ++ software are due to [lack of] memory security.

Rust is revolutionary, he said, because “Rust is the first consumer programming language that is efficient while maintaining memory security.” Lerche explained how Rust achieves memory security using the idea of ownership, based on a concept called affine logic, where each object has one and only one owner at a time.

Ownership rules are checked at compile time, so there is no runtime overload. Concurrency is also easier and safer in Rust than in C or C ++, resulting in additional performance and efficiency gains.

It sounds too easy. All developers and the IT community need to do is migrate to Rust and the code will run faster and more securely, global power consumption will decrease, and AWS will be able to shut down half of its data centers (although we did not hear this last idea during the session).

Big but

“But,” Miller said, “if we’re going to meet carbon reduction targets… we’re going to need most of the new software written in energy efficient languages ​​like C or Rust. But Rust has a somewhat noticeable learning curve… we see this adoption but we don’t see it everywhere.

Rust has a somewhat noticeable learning curve… we see this adoption but we don’t see it everywhere

“Where I see Rust growing the most is where there is an inordinate performance gain, so high volume database services, also in small, resource-limited environments like IoT and IoT. We don’t see it that much in: you’re writing a back-end for a JavaScript application.

The problem is, coding in Rust is difficult. One of the reasons that languages ​​like Java, JavaScript, and Python have been adopted so widely is that programmers can get productive faster.

So that’s the elephant in the room, “the famous learning curve,” Miller said. In a recent survey, “Among engineers who said they no longer use the language, 55% cited learning and productivity as the reason for dropping out. Experienced engineers need three to six months of study supported by a subject matter expert before they can be productive with the language.

Is there a possibility of reducing the learning curve? “Part of the challenge with the learning curve isn’t so much that it’s hard to use, but there are gaps in the developer experience, so we’re seeing comments from engineers that come from languages ​​like Java and trying to use Rust which they are uncomfortable with the debugger experience, ”Miller said, in response to our question. “Performance profiling tools aren’t the same they’re used to. And this is an area that we are studying.

“Rust came, historically, as a replacement for C ++,” Lerche added. “It was aimed at this use case. But what we’re seeing is that there are a lot of apps at a higher level.

“If you come to create a service, you go through Rust’s book which is very comprehensive and you will get into lives and traits and trait models and all these concepts that are part of the language but are not required to write a. service.” There are plans, he said, to write simplified documentation which is “what you need to know to write a service.”

While such initiatives are useful, it’s hard to imagine how Rust can become easy enough to learn that business application developers will be able to switch from Java or JavaScript, or C # or Python, when they have business issues to resolve. and can do more quickly in these other languages.

Also, further down the compute stack, the code is probably written in Rust, C, or C ++, because when it comes to the Linux kernel, or the core of a database engine, performance and high efficiency are already required.

However, the key point – that inefficient software is costly to the environment as well as to the customer – was well made and to which the IT industry is not paying enough attention, even though Rust did not. is only a small part of the solution. ®


Comments are closed.