/
Write
Start a team blog
NEW ✨
Start a team blog, invite your team, and start publishing.
AssemblyScript vs. Rust: Which Is Right for Your Wasm App?

Photo by American Public Power Association on Unsplash

AssemblyScript vs. Rust: Which Is Right for Your Wasm App?

Taurai's photo
Taurai
·Jan 11, 2022·

7 min read

Writing near-native applications for the browser often requires deep knowledge of JavaScript and its frameworks. This may be fine if you’re coming from a web development angle, but what if you’re a C++ systems developer looking to move your applications to the browser?

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 application behaviors 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, you will explore a deep comparison of both language options from an unbiased standpoint.

Comparing AssemblyScript vs. Rust

Since these are totally different programming languages, it’s necessary to normalize the comparison approach. This way, you don’t end up with an apples vs. oranges argument. To this end, review the following considerations when comparing Rust and AssemblyScript.

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 will need some added extensions to match.

On this front, Rust is a more mature programming language than AssemblyScript. The language certainty boasts more pronounced features#Features) than its counterpart by a wide margin. However, AssemblyScript is fast adding interesting features, such as Bootstrap and a standard library that extends JavaScript into Wasm, essentially building their tools toward becoming a Wasm go-to language.

2. Ease of Conversion

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.

AssemblyScript is widely taken as a variant of TypeScript’s syntax, which itself is a superset of JavaScript. This makes conversion easier if you’re coming from a strictly web development perspective. Rust, on the other hand, has some familiar accents with the C family of languages, blending a bit of JavaScript into the mix.

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 JavaScript team would make light work of an AssemblyScript application’s maintenance.

4. Popularity

The popularity comparison point simply assesses how easy it’ll 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 (often at no cost) 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.

5. Future

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

Wasm and Rust

Rust and WebAssembly have a detailed relationship that stems from the performance promises that made the Rust language popular. Rust has documented an elaborate process, with code, to set up and build your first Wasm application with their tool chain. Converting your Rust code into WebAssembly is facilitated by a Rust-built build tool, wasm-pack.

Performance

Rust avoids the slower garbage-collection feature associated with JavaScript and AssemblyScript. This means resulting applications perform faster than those made with AssemblyScript. With Rust, performance will hinge more on your coding 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. If you deploy the same application with both languages and follow the same design logic, the Rust-Wasm version will outperform that of AssemblyScript.

Documentation

Rust produces documentation in the form of books for start-to-finish learning and implementation experience. Each tool, along with their Wasm outfit, 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 and more closely tied responses could be a benefit for long-term support, you’re likely to get more help (and faster responses to issues) 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.

Handling or Converting Existing Applications

When you factor in existing knowledge of Rust into the documentation equation, this language becomes the most viable route. Since your applications will not need an altered version of Rust for development, you can branch existing projects into Wasm projects.

WebAssembly and AssemblyScript

AssemblyScript for Wasm

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.

Performance

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 make. AssemblyScript is very similar to TypeScript, offering a relatively shorter learning curve than Rust when you have any level of web development experience. How well your apps perform in the end is proportional to how well you know the language itself.

Documentation

Because it has a narrower usage area in comparison to Rust, you’ll find AssemblyScript’s documentation smaller in size. However, that works in its favor 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-attentive 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.

Handling or Converting Existing Applications

Porting existing applications into AssemblyScript is not too complex for developers that have a good grasp of JavaScript and TypeScript. In fact, you’ll be excused for mistaking some AssemblyScript for either TypeScript or JavaScript, save for some small details and specifications.

The case for converting existing applications into AssemblyScript and then Wasm is invalid because the programming language stands as a brand-new take on development for WebAssembly. This means that, unlike with Rust, all applications written in AssemblyScript are meant for WebAssembly.

Conclusion

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 flaunt your ideas, not necessarily the language used to develop them. This is why the itching question of complexity was deliberately left out of the comparison.

Expect Rust-Wasm 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 laid on the table, how well you enjoy either Rust or AssemblyScript and Wasm depends more on your developers’ skill 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 endeavor would be to make the minimum viable versions of your project with both Rust and AssemblyScript and weigh the experience. To best numb toolchain complexity, consider Suborbital, a platform for simplifying WebAssembly builds for simple deployment of complicated web services, no matter which tool you select.

All things considered, both Rust and AssemblyScript have compelling features and perks worth exploring when building Wasm applications. How well one serves you is largely a matter of preference and capacity that only hands-on development will bring into the light.