This article is more than 1 year old
Can Rust save the planet? Why, and why not
The snag: This programming language is safe and efficient, but hard to learn, impacting productivity
Re:Invent Here at a depleted AWS Re:invent in Las Vegas, Rust Foundation chairwoman Shane Miller and Tokio project lead Carl Lerche made the case for using Rust to minimize environmental impact, though said its steep learning curve made the task challenging.
Miller is also a senior engineering manager for AWS, and Lerche a principal engineer at the cloud giant.
How can Rust save the planet? The answer is that more efficient code requires fewer resources to run, which means lower energy usage in data centers and also in the environmental impact of manufacturing computing equipment and shipping it around the world.
Shane Miller and Carl Lerche speak on Rust efficiency and safety at this year's AWS Re:invent in Las Vegas
“Data centers consume … 1 per cent of all worldwide energy,” said Miller, though adding that the total energy consumed had changed little in ten years, thanks to technology advances and the fact that cloud tends to reduce the proportion of idle resources.
The second part of the argument is that Rust is among the most efficient programming languages. The source quoted for this is a 2017 paper [PDF] that measured the performance, memory usage, and energy efficiency of 27 programming languages, and placed C as most efficient, but Rust close behind with just three per cent more energy use. Java uses nearly double the energy, C# over three times, and Python over 75 times as much, according to the study.
This is an AWS conference after all
Still, this is not all that important since there is no doubting Rust’s efficiency, as a systems language, and Miller and Lerche did not rely solely on this research. Miller also referenced case studies from Discord and from Tenable that showed huge efficiency gains.
Garbage-collecting languages are inherently less efficient, said Lerche. Garbage collection is a common means of automating memory management and works by identifying objects that are out of scope and freeing their memory.
Why not just use C and C++? The reason is security and memory-related bugs, said Lerche, quoting research that “70 per cent of all high severity security vulnerabilities in software in C and C++ are due to [lack of] memory safety.”
Rust is revolutionary, he said, because “Rust is the first mainstream programming language that is efficient while maintaining memory safety.” Lerche explained how Rust achieves memory safety by 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 overhead. Concurrency too is easier and safer in Rust than in C or C++, leading to further performance and efficiency gains.
It seems too easy. All the developer and IT community needs to do is to migrate to Rust and code will run faster and more securely, world energy use will drop, and AWS can close half its data centers (though we did not hear this last idea during the session).
“But,” said Miller, “if we’re going to reach the carbon reduction goals … we’re going to need most new software written in energy efficient languages like C or Rust. But Rust does have a somewhat notorious learning curve … we are seeing that adoption but we are not seeing it everywhere.
Rust does have a somewhat notorious learning curve … we are seeing that adoption but we are not seeing it everywhere
This then is the elephant in the room, “the famous learning curve,” said Miller. In a recent survey, “of the engineers who said they were no longer using the language, 55 per cent cited learning and productivity as their reason for abandoning it. Experienced engineers require three to six months of study supported by a subject matter expert before they are productive with the language.”
- All change at JetBrains: Remote development now, new IDE previewed
- AWS is on the threshold of adulthood, but is nowhere near grown up
- AWS chops data transfer fees by massive extension of free tier – 2 months after rival previewed R2 Storage
- AWS claims 'monumental step forward' with optional IPv6-only networks
Is there any possibility of reducing the learning curve? “Part of the challenge with the learning curve is not so much that it is difficult to use, but there are gaps in the developer experience, so we’re seeing feedback from engineers who are coming from languages like Java and trying to use Rust that they’re uncomfortable with the debugger experience,” Miller said, in answer to our question. “The performance profiling tools are not the same as they are accustomed to. And that’s an area we are investigating.”
“Rust came, historically, as a replacement for C++," Lerche added. "It was targeted at that use case. But what we’re finding is that there’s a lot of application in a higher level.
"If you’re coming to build a service, you go through the Rust book which is very thorough and you will get into lifetimes and traits and trait patterns and all these concepts that are part of the language but aren’t necessary to write a service.” There are plans, he said, to write simplified documentation that is “what you need to know to write a service.”
Further, lower down the computing stack the code probably is written in Rust or C or C++, because when it comes to the Linux kernel, or the core of a database engine, high performance and efficiency is already a requirement.
That said, the key point, that inefficient software is expensive for the environment as well as for the customer, was well made, and something to which the IT industry pays insufficient attention, even if Rust is only a small part of the solution. ®