What is Rust?

In this part, there are a few insights here about Rust; if you’re not very familiar with it, or probably you want to refresh your memory. If not, feel free to go to the next section.

A brief history

Rust just celebrated five years of stable Rust. Thus, if you look back at the archives, you will realize that the project started much earlier than that – it takes a while for the software to evolve into something stable!

The first release label on the GitHub repository is over eight years old (release-0.1). And the first on this repository celebrates ten years today (I wasn’t indeed at university!). Before that, there was a Rust repository, which dates back to 2006.

It is also evident that two versions of Rust have been released within the five years: edition 2015 (Rust 1.0) and edition 2018 (Rust 1.31). Though the new edition was not a significant breaking change – one can use 2015 and 2018 packages in a Rust application – it shows a good velocity in the development of Rust.

Why Rust? Reliability, performance, productivity: choose three

Rust makes itself a practical programming language focusing on all of the reliability, performance, and productivity.

Performance means that Rust programs should run with no outflow in terms of memory usage or pure speed. Rust is collected as opposed to interpreted. An interpreted language like JavaScript or Python necessarily dodges a performance outflow, even with the best-in-class JIT customization. For illustration, dynamic typing prevents some compiler usage. Second, Rust uses manual memory operation, as opposed to a scrap collector. Even though scrap collectors can be structured with a low-speed overhead, it needs a lot more memory, like 5x more memory.

The downside of collected languages with manual memory operation is that, traditionally, C and C++ have been the primary source of security vulnerabilities because manual memory operation is complex. However, around 70% of severe vulnerabilities in software such as Chromium, Firefox, or Microsoft products are memory safety issues.

It is where Rust comes into existence; with a more potent model of memory power and borrowing ignited into the type system, Rust enables you to write dependable programs even with manual memory operation. It is the essential novelty of Rust, but as regards this series of posts, Rust has more benefits than that.

On the other side, there is a slight developer outflow in understanding how the power and borrowing rule works, but Rust has improved on the aspect. Thus, if you want to know about the performance, there is always some developer overhead: either you use a completely managed language such as JavaScript, but you will face challenges when your operation gets slow, or you either use something more efficient like Go or Java, and you can still end up fighting the scrap collector if RAM constrains you, or you use C/C++ which will be effective but will create a disadvantage later when security vulnerabilities are noticed in your software. You can also spend some time learning Rust, but after, you have to worry about neither reliability nor performance.

The next pillar of Rust is productivity. It comes by giving access to both low-position primitives – as we’ve seen with efficient memory operation and high-position abstractions – made possible with a robust type system. This ability to span the entire abstraction spectrum enables software development in Rust productive. If you write code and software performance as one, being more effective in writing reliable code increases the software performance.

In this talk, Bryan Cantrill discusses that a program written in Rust without applying all possible optimizations was 35% faster than an original well-optimized C program. The reason was that Rust enforced sorted maps as a B-tree under a good abstraction. While B-tree maps are very efficient, it is much harder to write a generic B-tree library in C than in Rust because of the type system, so C programs usually end up with few optimized structures like red-black trees. Another illustration is the Hash Map structure of Rust, which now implements a harborage of Google’s Swiss Tables, and is thus more efficient than stud::unordered map in C++. Relatively insightful! A good illustration is the following which compares the productivity of C and Rust to two languages that should not be compromised on performance.