Rust, a system programming language designed for performance, reliability and productivity, has created quite a stir in the software development community in recent years. Its growing popularity can in part be attributed to the Rust community’s catchy slogan: ‘Rewrite everything in Rust’. But what does this mean and why is it something that you might want to look into?

In the previous blog posts in this series, we provided a basic introduction to the world of Rust. Now, in this blog post, we will take a closer look at the advantages that Rust offers over other popular programming languages such as Java or Python. Our focus here is on why it may make sense in certain contexts to be bold and rewrite code in Rust or to develop new projects from the start in Rust.

Is rewriting code in Rust just a meme or is it something you should seriously consider?

The idea of rewriting existing code in Rust is more than just an Internet meme – it’s a serious trend in software development. The security and performance benefits that Rust offers have led many organisations to seriously consider using the language to replace or enhance existing code. Some of the biggest names in the tech sector, including Microsoft and Google, have publicly put their support behind Rust and are in the process of rewriting significant parts of their codebases in Rust. Open-source projects such as Firefox and Deno have also put a lot of effort into implementing their code in Rust. However, the idea of ‘rustifying’ everything is something that is not taken all too seriously in the Rust community. This has led to memes and jokes that overstate the amount of enthusiasm there is for Rust and the vision of a world where everything is written in Rust. That said, making the switch to Rust is both a serious trend in the tech sector and a cultural phenomenon within the programming community. It is under serious consideration in many projects, though it is also important to carefully weigh up the costs and benefits of making the switch.

Why rewrite everything in Rust?

The main reasons for rewriting programs in the Rust programming language can be divided into several categories that are closely related to the things I focused on in my first blog post:

  • Memory security: Rust is designed to significantly reduce the frequency of errors associated with memory accesses that often occur in other languages. The programming language allows developers to create safety-critical systems with minimal loss of performance.
  • Parallelisation: Rust offers amazing support for simultaneous and parallel code execution. This is particularly important in today’s digital landscape, where applications need to be able to utilise multiple processor cores efficiently. Rust’s inherent ability to prevent data races makes it ideal for applications that require high parallelism or concurrency.
  • Performance: Rust is designed to deliver a high level of performance, similar to that of C and C++, making it the perfect choice for system programming and other applications where performance is of the essence.
  • Powerful abstractions: Rust allows for a high degree of abstraction without compromising performance. These abstractions usually have no runtime costs, which means that they do not affect the performance of the code. This enables developers to write more elegant code that is easier to maintain.
  • Active community: Rust has an extremely active and constantly growing community that is releasing new libraries and tools all the time, which makes it easier to develop and maintain Rust code.

However, any decision to rewrite existing programs in Rust should always be made based on a careful analysis of the specific requirements and context, since this can be a resource-intensive undertaking. It is therefore recommended that you carefully weigh up both the benefits and the costs of taking this step.

Microsoft opts for Rust: changes at the core of Windows

Microsoft is working on a new implementation of core Windows libraries in Rust. David Weston, Vice President Enterprise and OS Security at Microsoft, announced that Rust will soon be implemented in the Windows operating system kernel. Making the switch to Rust is part of Microsoft’s efforts to reduce memory security bugs, which are responsible for around 70 per cent of security gaps in its products.

The process of rewriting code in Rust began in 2020 with DWriteCore, a text analysis, layout and rendering tool. The code for the tool is now written primarily in Rust, which has improved the performance of glyph substitution. DWriteCore now contains around 152,000 lines of Rust code and roughly 96,000 lines of C++ code. Along with that, the Windows graphics interface (Win32 GDI) is also ported to Rust. The latest version of Windows 11 boots with the Rust version that passes all GDI tests, though the Rust port is currently disabled behind a feature flag. Beyond the inferred improvement in security, the glyph substitution with OTLS (OpenType Library Services) performs five to 15 per cent faster. Although Microsoft is really enthusiastic about Rust, they are cautious about making a full switch to the programming language. ‘Windows will likely not be rewritten in Rust any time soon,’ says Weston. Nevertheless, Microsoft’s support for Rust gives a boost to the language and benefits the open-source community. Developers working in the industry see Microsoft’s switch to Rust positively. Samuel Colvin, founder of Pydantic, stresses the importance of Rust for high-performance, low-level applications and is excited to have Microsoft’s support. As he explained, ‘I am impressed by Microsoft being this forward thinking, but not very surprised. I am sure they are under pressure from their engineers to adopt Rust. If you are building an application today that is either performance critical or low-level, then Rust is a no-brainer at that point.’ Colvin said that while good Rust engineers are not easy to find, he believes it is still easier to find good engineers for Rust than for C/C++.

To find out more, check out this video: https://www.youtube.com/watch?v=8T6ClX-y2AE

Rewritten in Rust tools

In the section to follow, we would like to present a number of projects that have taken the bold step and initiated a complete rebuild in Rust. These projects demonstrate the growing confidence in Rust as a powerful and efficient programming language that is suitable for both existing systems and new developments. This is just a small selection of interesting projects, of which there are countless more.

  • Firecracker: This is an open source virtualisation project initiated by Amazon Web Services (AWS). Originally implemented in C++, much of the code was rewritten in Rust to provide enhanced security guarantees.
  • Servo: This is an experimental web browser engine developed by Mozilla. Although some parts are written in C++, the majority of the project was implemented in Rust.
  • Sudo RS: A security-centric, memory-safe redesign of the sudo and su commands in Rust. It is designed to serve as a seamless, secure replacement for popular use cases.
  • Deno: A secure runtime environment for JavaScript and TypeScript based on the V8 JavaScript engine and the Rust programming language. It was developed by Ryan Dahl, the original creator of Node.js, and represents a ‘reconception’ of Node.js, revisiting many of design decisions originally made when creating Node.
  • uutils coreutils: A new cross-platform implementation of the GNU coreutils in Rust, with the goal of being a seamless replacement for the GNU utils. It is designed to work on many platforms such as Linux, Mac and Windows, making it easy to transfer scripts between these platforms.
  • Discord: Discord switched from Go to Rust to improve performance and efficiency. This primarily involved the ‘Read States’ service, which was negatively impacted by Go’s memory model and garbage collector. Rust’s ownership model for memory management eliminated performance peaks and improved memory management. Rust was already being used successfully in Discord’s software infrastructure, so making the switch seemed like a natural step. By migrating to Rust, Discord improved latency, CPU and memory utilisation and made programming more efficient. In addition to enhanced performance, Rust also offers advantages for the engineering team, enables refactoring and has an excellent ecosystem and tools.

Outlook

In summary, as the example of Discord shows, switching to Rust can bring significant benefits for many organisations. From performance improvements to memory and type safety, Rust offers a host of features that can improve both the productivity of developers and the user experience. However, it is important to note that switching to Rust, or for that matter any other programming language, does come with its challenges. It takes time, requires resources and involves a learning curve for the developers. It is therefore important that you consider the specific needs and context of your project before making such a decision.

Finally, while the ‘Rewrite Everything in Rust’ movement presents a strong argument, it is not to be taken it literally. Every technology has its strengths and weaknesses, and it is important to choose the right one for the right problem. The use of Rust is an exciting trend in software development, and we look forward to seeing how the language evolves and how it will be used in future. Switching to Rust cannot fix every problem, but for many it can be a great tool to improve the performance, security and maintainability of their software.

Would you like to learn more about exciting topics from the world of adesso? Then check out our latest blog posts.

Also intersting

Picture Marc Mezger

Author Marc Mezger

Marc Fabian Mezger is an AI Specialist Consultant specializing in Medical Deep Learning, Computer Vision and Drift. In his current role at the AI & Data Science Competence Center, he is responsible for advising customers on AI solutions and their implementation. He has extensive knowledge in Machine and Deep Learning.

Picture Moritz Momper

Author Moritz Momper

Moritz is a Data Engineer at adesso. He specialises in Python-based data engineering and backend development in Go to create innovative solutions for data processing and analysis.

Category:

Methodology

Tags:

Rust

Save this page. Remove this page.