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

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.

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

The research is problematic, as several at the session on Monday observed, not because of lack of care, but because languages have many implementations and compilers, some of which are more efficient than others. It is also odd to find TypeScript 10 times less efficient than JavaScript, considering that it compiles to JavaScript and similar code can be written in both.

Still, this is not all that important since there is no doubting Rusts 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.

In the Tenable case, a JavaScript component was rewritten in Rust and achieved a 50 per cent improvement in latency, a 75 per cent reduction in CPU usage, and a 95 per cent reduction in memory usage. Its kind of crazy, said Miller. Its substantial savings, not just in infrastructure, it translates into savings in energy.

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.

The garbage collector is going to have to pause the process to do the garbage collection pass. And when it's paused the service is not able to respond anymore to requests, he said. This means languages such as 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, 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 were going to reach the carbon reduction goals were 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

"Where Im seeing Rust growing the most is where theres an outsized performance gain, so high volume database services, also in small resource-constrained environments like IoT and embedded. Were not seeing it so much in: youre writing a back-end for a JavaScript app.

The problem is that coding in Rust is hard. One reason why languages like Java, JavaScript, and Python have seen such wide adoption is that programmers can become productive more quickly.

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.

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 were seeing feedback from engineers who are coming from languages like Java and trying to use Rust that theyre 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 thats an area we are investigating.

Rust came, historically, as a replacement for C++," Lerche added. "It was targeted at that use case. But what were finding is that theres a lot of application in a higher level.

"If youre 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 arent 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.

Although such initiatives will be helpful, it is difficult to envisage 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 problems to solve and can do more quickly in those other languages.

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.

Read more here:
Can Rust save the planet? Why, and why not - The Register

Related Posts
This entry was posted in $1$s. Bookmark the permalink.