Author: Wu Linhui (Wuling) The Alibaba delivery technology team first paid attention to Rust ️ because the Atom team gave up maintaining Atom and turned to the development of a new lightweight, faster editor Zed, and this editor has the largest The characteristic is that it will

2024/06/2720:55:33 technology 1887

Author: Wu Linhui (Wuling) Alibaba's delivery technology team

first paid attention to Rust ️ because the Atom team gave up maintaining Atom and turned to the development of a new lightweight, faster editor Zed, and this editor The biggest feature of the server is that it will be built entirely based on Rust. And why developing based on Rust can be faster? This successfully attracted my curiosity and is the reason for writing this article.

In the past two years, Rust is rapidly occupying the field of front-end infrastructure. Popular tools such as Webpack, Babel, and Prettier all have Rust alternatives, and the performance has been improved by 10 to 100 times. Amazon and FaceBook all recognize it as the best alternative to C/C++ in their systems. Microsoft even believes that Rust, as an industrial-grade development language, should be the first choice in the field of cloud infrastructure. Figma and Dropbox also already use Rust in their clients. It is even said that any application system that can be implemented in Rust will eventually be implemented in Rust.

In this year's StackOverflow developer survey, Rust has been the most popular language among developers for 7 consecutive years. But Rust doesn’t stop there. It has more applications in related fields. Let’s first look at the applications of Rust in related fields, and then focus on why everyone chooses Rust.

1. Application of Rust in related fields

1.1 Front-end infrastructure field

  • SWC: (Speedy Web Compiler) The front-end construction tool based on Rust can be understood as the Rust version of Babel, but the performance is improved by 10 times. Currently used by Next.js and Deno.
  • Tauri: Tauri is currently the most popular alternative to Electron. It successfully solves the problems of Electron's large package size and high memory usage by using Rust and Webview2. For details, please see the reference article at the bottom, why Microsoft finally gave up on Electron. I believe that the Atom team also saw the success of Tauri and decided to make the Zed editor based on Rust.
  • Rome: It can be understood as the new work of the author of Babel. Rome aims to replace many existing JavaScript tools and integrates code detection, packaging, compilation, testing and other functions.
  • Parcel: A zero-configuration build tool, characterized by fast compilation and no configuration required.

1.2 Data visualization field

  • Wgpu: It is a Rust implementation of the WebGPU API standard. WebGPU is a specification published by W3C with the goal of allowing web code to access GPU functionality safely and reliably. Its implementation is based on the Vulkan API and will be translated to various APIs used by the host hardware (such as DirectX, Metal, Vulkan, etc.) for execution.
  • Bevy: A data-driven game engine developed based on Rust language. Supports both 2D and 3D graphics rendering, as well as graph visualization rendering.
  • Cube.js: cube.js is an open source BI analysis tool framework. The Cube Store is used for performance optimization of analytical queries and additional functions such as data federation through cross-database connections, which are implemented by Rust.

Rust's high performance and combination with WebAssembly are very suitable for use in the field of data visualization that requires large amounts of data processing.

1.3 Rust and Node Ecology

  • Deno: Deno is a simple, advanced and safe JavaScript and TypeScript runtime environment based on the V8 engine and built with the Rust programming language.
  • Napi-rs: Use Rust and N-API to develop high-performance Node.js extensions, which can replace the Node.js extension previously developed in C++

1.4 Web3 domain

Since the Web3 protocol needs to be fast when processing tens of millions of untrusted inputs And with powerful performance, Rust has obvious advantages. Functionally complex tasks can be handled with good performance while reducing errors related to memory, bounds, null variables, initialized variables or integer overflows.
uses Rust to create more powerful DApps (distributed applications), which can reduce many common errors and make DApps run as expected after release. Rust’s performance advantages and security make Rust an ideal choice for Web3 applications. Among them, Binance’s matching engine uses Rust as the main language, and the Solana community has many DApps developed based on Rust.

1.5 Rust, as the main language of automotive software, explores the hard real-time performance and perfect memory mechanism of

Rust, which is also suitable for software development in automotive scenarios. At RustChinaConf, Guoqi Intelligent Control shared its exploration and sharing of Rust in automotive software development.

2. Advantages of Rust

Author: Wu Linhui (Wuling) The Alibaba delivery technology team first paid attention to Rust ️ because the Atom team gave up maintaining Atom and turned to the development of a new lightweight, faster editor Zed, and this editor has the largest The characteristic is that it will  - DayDayNews

As early as 2015, Mozilla employees released Rust. It is a multi-paradigm programming language focused on security and performance. It is built with speed and efficiency in mind, which means it can provide zero cost. abstraction, inheritance, and functional features.

Rust helps developers create fast, memory-saving software. It is a modern alternative to C++ or C that also focuses on code safety and concise syntax.
Rust is very different from JavaScript. JavaScript will find unused variables and objects and automatically clear them. This mechanism is called garbage collection, and Rust expects developers to plan manual memory management themselves.

2.1 High performance

All programs must manage how they use computer memory while they run. Some languages ​​(such as JavaScript) have garbage collection mechanisms that constantly look for memory that is no longer used when the program is running. In other languages, programmers must allocate and release memory themselves.
Rust chose the third method: managing memory through the ownership system, and the compiler will check according to a series of rules during compilation. If any of these rules are violated, the program will not compile. It is this memory management mechanism that gives Rust amazing memory utilization.

let s1 = String::from("hello");let s2 = s1; // s2 borrows s1, s1 is no longer valid println!("{}, world!", s1); // Rust will report an error here, s1 is an invalid reference 

2.2 Reliability

Rust's rich type system and ownership model ensure memory safety and thread safety, allowing you to eliminate various errors at compile time.

  • memory safety: Usually memory insecurity includes: null pointer, wild pointer, dangling pointer, use of uninitialized pointer, illegal release, buffer overflow , execution of illegal function pointer, data race, etc. Rust manages memory through an ownership system that the compiler checks against a series of rules at compile time. If any of these rules are violated, the program will not compile.
  • thread safety : Thread safety is a term in programming, which means that when a certain function or function library is called in the multi-threaded environment, it can correctly handle the shared variables between multiple threads , so that the program functions Done correctly. Rust forces these threading problems to be exposed at the compile stage through a complete set of infrastructure and type checking. Rather than spending a lot of time trying to reproduce the specific situation where the runtime concurrency bug occurs, Rust will refuse to compile incorrect code and provide errors that explain the problem. information.

3. Rust’s steep learning curve

Rust has a steep learning curve, which is also the difficulty Rust currently faces in large-scale use. Many friends will joke that it is not difficult to get started with Rust. I have started it hundreds of millions of times. A joke circulating on the
Internet vividly describes the technical complexity of Rust.

Xiao Wang is a C++ engineer working on a large project. Today he triggered a full compilation at work and went home. He will come back tomorrow.
Xiao Zhang is a Python engineer for deep neural network . Today he changed a parameter at work and started training, then went home and will come back in three days.
Xiao Li is a senior Rust engineer. It only took him one hour to complete the development of requirements at work today.
then worked overtime for three consecutive nights before the compilation passed.

The picture shows the learning curve of Rust:

Author: Wu Linhui (Wuling) The Alibaba delivery technology team first paid attention to Rust ️ because the Atom team gave up maintaining Atom and turned to the development of a new lightweight, faster editor Zed, and this editor has the largest The characteristic is that it will  - DayDayNews

As front-end infrastructure is gradually Rust-ified, Rust becomes more and more important in the research and development of front-end infrastructure, and Rust will be valued more and more when recruiting. In various comparisons of
front-end tools, the use of Rust modification has achieved more than 10 times performance improvement. It is an unstoppable trend for Rust to become the infrastructure for front-end R&D. You can start learning from now on and eat the Rust crab together.

Appendix link

[01] Microsoft's article on cloud security, best industrial application products: Microsoft: Rust Is the Industry's 'Best Chance' at Safe Systems Programming – The New Stack

[02] Rust is the future of JavaScript infrastructure Rust is the future of JavaScript infrastructure

[03] In just 4 years, Microsoft finally gave up on Electron. In just 4 years, Microsoft finally gave up on Electron

[04] Solidity, Go, Haskell, Rust, which programming languages ​​do Web3 developers master? More advantages? Solidity, Go, Haskell, Rust, which programming language is more advantageous for Web3 developers to master? - Foresight News

[05] Rust is the future front-end infrastructure: GitHub - i5ting/rust-fe: Rust is the future front-end infrastructure

technology Category Latest News