The Svelte Core team ponders the Rust compiler to speed up web applications

According to its creator, the next major release of Svelte, the increasingly popular web application framework, could benefit from the Rust programming language. Rich Harris.

Among the possible changes for the eventual release of Svelte 4.0 is a new compiler, written in Rust, Harris said, in a video interview produced by web development tools provider Vercel, where Harris is currently employed.

“A lot of JavaScript tools are written in Rust right now, and maybe it would make sense if the Svelte compiler was written in Rust,” Harris said. He stopped short of a full commitment to moving to Rust in this next release, though he indicated that was a promising approach the core development team was exploring.

Currently, Svelte works by compiling web application code (built from HTML, CSS, and JavaScript) into highly optimized JavaScript. It differs from popular JavaScript frameworks like React.JS and Vue which render complex web pages when running in the browser. It eliminates this tedious step by moving most of the rendering work out of the browser, by compiling the application in advance.

Despite Svelte’s potential performance improvements, Harris has heard grumblings about the very large code sizes that result from very large web applications. Svelte compiling code for large web apps, for example, tends to be larger than a similar app’s component code rendered in React, a third party has found.

A Rust-based approach to compiling code could potentially “not only eliminate this problem, it could actually mean that the compiled code is smaller than the input code, which I think would be quite unique”, has said Harris. The resulting code would still be in JavaScript.

Although a bit difficult to learn, the Rust language is quickly being adopted by system designers, not only for its fast performance, but also for its security controls. To that end, Harris noted that switching to Rust “potentially opens the door to error bounds.”

Catch up with React

The core team is also researching a number of other potential enhancements, including the incorporation of “partial hydration approaches.”

Harris also wants to continue exploring Svelte’s support for rendering motion. “It’s something Svelte has always prioritized,” Harris boasted. Svelte has declarative transitions to make it easy to add or remove an element from the browser’s Document Object Model (DOM). “We are not going to immediately remove the element from the DOM. We can play a transition on it so you get graceful in, out, in and out behavior,” he said.

Despite these advanced features, Harris jealously watches React’s Framer Motion library for producing animated layouts. “I think if a framework treated these things as its domain, then you could do a really nice UI design with minimal effort,” he said.

The current version of Svelte (v3) was released in April 2019, and new versions arrive every year and a half or so. The release date for Svelte 4.0 has not yet been publicly set.

Watch the whole interview here:

Comments are closed.