Rust — A Green Language for 21st Century

Roger Kelly
3 min readFeb 5, 2020

--

Could Rust be part of the solution for climate change? After reading Danny Van Kooten’s story https://dannyvankooten.com/website-carbon-emissions/ about your website’s carbon footprint as it relates to Javascript, I started thinking about the backend systems created since the time of Java and other more dynamic languages’ rise around 1999.

The evolution of computer languages over the past 20–25 years ago has provided developers with better, safer and more productive means of producing software. Moving the clock back to around 1997 most development was happening in the C/C++ space was very painful to build systems in for most cases. With the introduction of Java/Python/Ruby in the late 1990s developers were offered a more productive and safer means of writing code. The shift in focus was so dramatic and complete that we forgot so many of the problems from C/C++ that Java and all of the other languages (Python, Ruby, Node.js, etc). solved.

At the expense of efficiency, CPU, and memory we solved so many very difficult issues that had plagued the software development discipline since the 1980s — memory leaks, unsafe memory access, crashes and long/complex builds and hard library binary linkage issues, build times, hard to maintain code.

The tradeoff has been the need for much larger computers and more of them to scale out to meet the resource hungry modern languages. We solve the performance problems of less efficient languages by have larger memories, more CPU cores, more processes and more physical computers. Algorithms that need to scale now do so over multiple physical computers. Much of this is due to the inefficiencies in our current toolset of languages mentioned above. Memory is managed through garbage collectors that eat up lots of unneeded memory, interpreted code uses more and more CPU, JIT compiling takes cycles also. In doing so we use more electricity and thus a much larger carbon footprint to do computing that could have been done with less energy use if the application ran more efficiently.

Rust solves so many of the original problems from C/C++ that we ran away from about 20 years ago. Safe memory access, concurrency, easy build process and packaging and very smart compiling while delivering a native executable with the memory and CPU efficiency of C/C++. It is time to revisit much of the past 20 years of backend server side development — in particular Java systems that eat up lots of resources (looking at you Spark).

We ran away from two really good things also when we left C/C++ — speed and efficiency. And this spawned the allocation and usage of lots and lots of physical computers gobbling up lots of kilowatts.

I recently rewrote an intensive task in our data pipeline that processed 1.8 billion records and needed a 47 million record lookup for each. The results for the lookup caching build for some popular languages was like this:

  • C Python: 5min 29 sec. 5.8G
  • PYPY3: 4 min / 10g
  • Java: 2min 2 sec 8G memory
  • Rust: 1min 33 sec 2.9 G used

This is the type of efficiency you can expect from Rust. It is far faster and a fraction of the memory footprint. Each reduction in memory and CPU for a process scaled over a whole data center’s worth is a lot of computers burning lots of kilowatt hours. Oh and not to mention everything ran faster with smaller memory footprint!

Fewer computers equals less energy consumption and less greenhouse gases. Rust could be the greenest computer language to be introduced yet.

In closing check out this quote from the above mentioned article.

Shaving off a single kilobyte in a file that is being loaded on 2 million websites reduces CO2 emissions by an estimated 2950 kg per month.

Our backend code likely burns way more electricity than this and does it at scale. If we could move to Rust — our resource consumption would much smaller and reduce CO2 emissions.

Give Rust a try next time you consider something new that needs to be fast and performant. You might be helping out the environment at the same time also!

--

--