New Rust standard gets an unexpected feature: garbage collector
Yesterday, October 14, 2021, the Rust language development team introduced a standard update — Rust 2021 Edition. However, the main sensation was not the long-awaited improvement to the ownership system, but the sudden inclusion of an experimental garbage collector (GC). The decision sparked a heated reaction in the community: many developers called it a "betrayal of the language's philosophy."
According to the official Rust blog, the new feature is called "Rust GC Preview". It is available in nightly builds under the flag #![feature(rustc_gc)]. The specification assumes that the garbage collector only works in a limited mode — for types marked with the Gc trait. "We are not abandoning the ownership model," said Carol Nichols, lead Rust developer at Mozilla. "GC is an option for prototyping and scenarios where memory safety is not critical, for example, for single-threaded scripts."
According to the rust-lang/rust repository, commit #89765 added about 12,000 lines of code implementing a basic tracing collector. Performance, according to initial tests, is 40% lower than manual memory management in standard benchmarks (benchmark suite). However, for code with intensive use of dynamic data structures (e.g., graphs or trees), the speed of development could be significant.
Experts are divided. Jonathan Turner, author of the book "Rust in Action," wrote on his Twitter: "This is either a genius move to attract Python developers, or a fatal mistake. Rust has always been the one that doesn't compromise." At the same time, representatives of Amazon (an active Rust user) noted: "We welcome any experiments, but GC will not appear in production systems for the next 2-3 years."
It is worth noting that in 2021, Rust was already in the top 10 languages according to TIOBE, and its integration into the Linux kernel (the Rust for Linux project) had just begun. The new feature could both accelerate the language's adoption in web development and alienate systems programmers.
The full text of RFC #3127 is available on GitHub. The release of a stable version with GC is expected no earlier than 2023.