WebAssembly (Wasm) is a binary format compile destination for applications written in system programming languages, like C, Rust, and Go. The objective is to import those standalone language behaviours and features (power) into web browsers. Wasm achieves this without installation and system spec limitations, as would be the case with regular desktop applications.
You’ll appreciate the power of Wasm when you see a full-featured tool, like AutoCAD, in the web browser.
This post is primarily for developers looking to include the high-performance and native features associated with desktop applications in the browser. For that purpose, you’ll find either Rust or AssemblyScript very appealing, depending on your foundational skill set. In this article, we will explore a comparison of both language options.
1. Language Features
Perhaps the most important consideration when deciding between Rust and AssemblyScript to build Wasm applications is their features. The question you’ll need to answer is what each of these languages can achieve that the other would need a workaround to match.
2. Ease of Adoption
If you’re looking to make a change toward using either AssemblyScript or Rust, you may want to consider how steep their relative learning curves will be. This, of course, varies from one developer to the next. However, in the event that you’re working with a team, skills lag will significantly affect your productivity.
3. Ease of Maintenance
Choosing a language to build your Wasm applications is the first step in a long commitment. Consider how often you’ll need all hands on deck, how much that will cost you, and how much the maintenance effort is overall.
With Rust developers fetching north of $100,000 per year, you’ll certainly need to account for that as a maintenance factor. Conversely, a seasoned web development team would make light work of an AssemblyScript application’s maintenance.
The popularity comparison point simply assesses how easy it would be to build a team dedicated to either Rust or AssemblyScript. The more popular programming language brings a larger community of developers into the mix—a resource you can leverage when building your applications.
Rust has been the most popular and loved programming language for over five years in a row. The growing popularity, new developers taking the language up, and more applications being written in the Rust language make it the more popular option.
This comparison point ties in with a programming language’s age. Consider how much older (in years) Rust is over AssemblyScript and how much work has gone into their respective growth to make better Wasm applications.
AssemblyScript has branded all efforts as being “made for WebAssembly.” That’s hard to fight. Rust simply includes Wasm as part and parcel of a grand plan. If you had to pick one on this basis alone, AssemblyScript, and the fact that they have more Wasm features in the pipeline, would be the way to go.
WebAssembly and Rust
Rust and WebAssembly have a detailed relationship that stems from the performance promises that made the Rust language popular. Rust has documented how to set up and build your first Wasm application with their toolchain. Converting your Rust code into WebAssembly is facilitated by Rust build tools like Cargo and wasm-pack.
Rust's unique memory guarantees and performance-oriented runtime allows it to achieve better performance than AssemblyScript in many cases, though this is highly dependent on your use-case and the optimizations that you apply to each language's toolchain. For more details, I'd highly suggest checking out this post. With Rust, performance will hinge more on your code design and the size of your application than, say, any feature you don’t take advantage of. While this is partly true of AssemblyScript as well, Rust’s diverse language features and perks provide the leverage needed to make a better application overall.
Rust produces documentation in the form of books for start-to-finish learning and implementation experience. Each tool, along with their Wasm capability, can be introduced and used with a Quick Start Guide and a walkthrough experience that leaves teams with a Wasm project in hand.
When you compare the community surrounding Rust to that of AssemblyScript, it is obvious that the former dwarfs the latter. While AssemblyScript’s Discord (which is quite Wasm-focused) could be a benefit for quick support, you’re likely to have more resources building with Rust because of the already large community backing it. Speaking of the long term, you’d also want to compare how well your projects are supported so that you don’t have to be the one to experience the first problem instance.
Converting Rust Applications
It's worth noting that if your team has existing projects built with Rust, this language is the most viable route. Your applications will not need an altered version of Rust for development, so you can branch existing projects into Wasm projects.
WebAssembly and AssemblyScript
The biggest case for AssemblyScript and Wasm is that the language was built specifically for porting features into the browser. This makes learning AssemblyScript a good path if all you plan to do is focus on building on its features.
As more features and support pile up on the AssemblyScript project, the language is fast catching up with Rust, as far as performance is concerned. However, this can also depend on what you’re trying to build. AssemblyScript is very similar to TypeScript, offering a relatively short learning curve compared to Rust when you have any level of web development experience.
Because it has a narrower use-case in comparison to Rust, you’ll find AssemblyScript’s documentation smaller in size. However, that works in its favour since all of it pertains to Wasm application development.
The lightweight nature of AssemblyScript, relative to Rust, makes it a better option for non-resource-intensive projects. However, if you were building a game, for example, with multiple dependencies and a heavy codebase, try Rust. The documentation and community limitations of AssemblyScript in that instance would only make your work all the more difficult.
Converting TypeScript Applications
By now, you likely know which language is the better option for your WebAssembly projects, mostly based on how comfortable you are with learning the nuances of either option. When well written, your in-browser applications should showcase your ideas, not necessarily the language used to develop them. This is why it's important to choose the language that's most comfortable for your team and most useful for your application.
Expect Rust applications to exude better performance than those made from AssemblyScript. However, with the lightweight feature and the web technology familiarity associated with AssemblyScript, you’ll likely start testing and deploying faster than with Rust.
With all benchmarking variables put aside, how well you enjoy either Rust or AssemblyScript with Wasm depends more on your developers’ skillset and the project scope than either language itself—as programming should really be. It boils down to how well you can wield the language and tools you choose.
A more interesting endeavour would be to build the minimum viable versions of your project with both Rust and AssemblyScript to weigh the experience. All things considered, both Rust and AssemblyScript have compelling features and perks worth exploring when building Wasm applications. How well each one serves you is largely a matter of preference and capacity that only hands-on development will bring into the light.