> BE FEARLESS Why Rust-lang is your ticket to stable, high-performance web applications _
Started career as a Frontend Engineer @ Alimama (advertise group in Alibaba Inc.) WHO AM I Started a pure-Rust project My first in production Rust project A full-time Rust engineer @ City Brain team, Aliyun
Started career as a Frontend Engineer WHY Rust Thought Frontend is easier Than java, CPP…
Started career as a Frontend Engineer WHY Rust Thought Frontend is easier Than java, CPP… Frontend is much much harder
Why Is Frontend Hard • Too many caveats • Hiding many details behind the scene • Growing too fast, new tech every year
Started career as a Frontend Engineer @ Alimama (advertise group in Alibaba Inc.) Started a pure-Rust project • @ 2016 • We Needed a fast, stable image-generator service for the Taobao App frontpage • Called Minolta
Node.js Our Need • Too many caveats • Is this fast enough? Are we profiling the right way?? Is multi-process/ multi-threading really helping? • Hiding many details behind the scene • ASync file IO ? Really? Does Promises have overhead? Will this 3rd-lib crash? • Growing too fast, new tech every year • Should we move to async/await? • Be cool or be fast?
• Can we easily know how the code we wrote is executed? • Can we know whether the code / deps will crash / error or not? • Can we know whether the runtime is optimizing our code or not?
Rust Our Need • Strong-typed, compiled language One of the fastest Clear thread model • Is this fast enough? Are we profiling the right way?? Is multi-process/ multi-threading really helping? • Raw, clear async model Zero-overhead async (futures) Static Error handling / crash detection • Async file IO ? Really? Does Promises have overhead? Will this 3rd-lib crash? • Growing fast, remain stable Both cool and fast! • Should we move to async/await? Be cool or be fast?
Minolta (Rust) Co-work with @ 4800 RPS 82% CPU 5.86% MEM Battle tested Went through two 11.11 No critical crash down First Rust project In production As we know, in Alibaba
Minolta (Rust) Co-work with @ • It’s a CPU-bounded web application. • It interacts with some C-only libraries (freetype, cairo, librsvg…) • It needs to download resources on every request, and properly handle many different error kinds • We got 20x speedup compared to the Node.js version
Confetti (Rust) 6000 RPS 24MS RT GPU rendered on Server Next-gen graph rendering Inspired by Pathfinder (Mozilla)
Smash (Rust, WIP) Distributed Graph Computation Based on Naiad Paper High performance city simulation Less than 8ms per iteration Blazing fast messaging Strong network I/O guarantee WASM speeded up client
If U need Frontend Backend IO heavy CPU heavy High level System level Exp first Lang insurance
RUST Rust empowers you to reach farther, to program with confidence in a wider variety of domains than you did before.
RUST PERFORMANCE RELIABILITY • Fast & memory efficient • Borrow checker (@ Compile time!) • No runtime, no gc • Lifetime • C-FFI support, easy for embedding • Strong guarded thread safety
WHY YOU COULD BE FEARLESS WITH RUST?
RUST OWNERSHIP OWNERSHIP ENABLES IT REMOVES • RAII Style deconstructors • A source of memory leaks • No dangling pointers • Many NullPointerException • No data races • Fearless multithreading
RUST GUARANTEE Send Sync • Variable could be send from thread A to B • Variable could be shared between threads without a memcpy • Auto added to most types • Not available for thread-local, e.g. Rc • Mutex, Atomic • Concurrent data structures!
These are problems In C++, not JS!
Popular in FE IT REMOVES • Typescript • Countless type check and unsafe • React / Redux • Too many logic modifying data • Immutable • Data mutable hard to track • …
Rust makes me a Better programmer
Rust feature IT ENABLES • Ownership / Lifetime • Early drop unused variables • Immutable first • Unexpected mutation • Weak Ref / Global Statics • Better memory management • Fearless concurrency • Thread support (Upcoming) • … • …
When Threads are adopted in WASM, Rust would almost be the only choice to write confidence, zero-cost multithreaded logic in WASM
Ouch… This article is quite popular
Can you optimize This hard every time?
@ Jandem I work on SpiderMonkey JS performance (and got mentioned in the article for fixing a perf bug!) and this is exactly the point I wanted to make. If you're not a VM engineer, it's much harder to write fast JS. Wasm also gives you much more predictable performance across engines, without requiring (often engine-specific) 'hacks' like function cloning.