AssemblyScript
{{Short description|TypeScript-based programming language}}
{{Use mdy dates|date=February 2021}}
{{Infobox programming language
| name = AssemblyScript
| logo = AssemblyScript logo 2020.svg
| logo size = 125px
| screenshot =
| screenshot caption =
| paradigms = Multi-paradigm: functional, generic, imperative, object-oriented
| family = ECMAScript: JavaScript: TypeScript
| designer = Daniel Wirtz,{{cite web|url=https://github.com/AssemblyScript/working-group|title=AssemblyScript Working Group|author=|date=2020-04-24|website=GitHub.com|publisher=AssemblyScript Project|access-date=2021-02-10|quote=Daniel Wirtz (@dcodeIO) - Author of AssemblyScript}} Max Graey{{cite web|url=https://www.youtube.com/watch?v=ZlL1nduatZQ|title=WebAssembly for Javascript Developers|last1=Turner|first1=Aaron|date=March 28, 2019|website=YouTube.com|publisher=WebAssembly SF|access-date=2021-02-10|quote=@dcodeIO [Daniel Wirtz] and @MaxGraey [Max Graey]—they’re the main two developers of AssemblyScript}}
| developer = The AssemblyScript Project
| released = {{Start date and age|2017}}{{cite web|url=https://www.npmjs.com/package/assemblyscript/v/0.1.0|title=assemblyscript 0.1.0|author=|date=2017|website=npmjs.com|publisher=AssemblyScript Project|access-date=2021-02-10}}
| latest release version = {{wikidata|property|preferred|references|edit|Q105690185|P348|P548=Q2804309}}
| latest release date = {{Start date and age|{{wikidata|qualifier|preferred|single|Q105690185|P348|P548=Q2804309|P577}}}}
| latest preview version =
| latest preview date =
| typing = Static
| scope = Lexical
| programming language =
| platform =
| operating system =
| license = Apache 2.0{{cite web |url=https://github.com/AssemblyScript/assemblyscript/blob/master/LICENSE|title=License|author=|date=2017-09-29|website=GitHub.com|publisher=The AssemblyScript Project|access-date=2021-02-10|quote=AssemblyScript/assemblyscript is licensed under the Apache License 2.0}}
| file ext = {{mono|.ts}}
| file format = text, Unicode (source)
WebAssembly#Code representation (object)
| website = {{URL|www.assemblyscript.org}}
| implementations = {{mono|asc}} (AssemblyScript compiler)
| dialects =
| influenced by = JavaScript, TypeScript, WebAssembly
| influenced =
}}
AssemblyScript is a TypeScript-based programming language that is optimized for, and statically compiled to, WebAssembly (currently using {{mono|asc}}, the reference AssemblyScript compiler). Resembling ECMAScript and JavaScript, but with static data types, the language is developed by the AssemblyScript Project{{cite web|url=https://github.com/AssemblyScript|title=The AssemblyScript Project|author=|website=GitHub.com|publisher=The AssemblyScript Project|access-date=2021-02-10}} with contributions from the AssemblyScript community.
Overview
In 2017, the availability of support for WebAssembly, a standard definition for a low-level bytecode and an associated virtual machine, became widespread among major web browsers, providing web programs a lower-level and potentially higher-performance compiling target for client-side programs and applications to execute within web browsers, along with the interpreted (and in practice dynamically compiled) JavaScript web scripting language.{{cite web|url=https://webassembly.org/roadmap/|title=Roadmap|author=|date=November 2017|website=WebAssembly.org|publisher=WebAssembly Community Group|access-date=2021-02-10}} WebAssembly allows programs and code to be statically compiled ahead of time in order to run at potentially native-level or bare machine (metal) performance within web browsers, without the overhead of interpretation or the initial latency of dynamic compilation.{{cite web|url=https://webassembly.org/|title=WebAssembly|author=WebAssembly Working Group|website=WebAssembly.org|publisher=WebAssembly Working Group|access-date=2021-02-10}}
With the adoption of WebAssembly in major web browsers, Alon Zakai, creator of Emscripten, an LLVM–Clang-based C and C++ compiler that targeted a subset of JavaScript named asm.js, added support for WebAssembly as a compiling target in Emscripten, allowing C and/or C++ programs and code to be compiled directly to WebAssembly.{{cite web|url=https://emscripten.org/|title=Emscripten|last1=Zakai|first1=Alon|author2=Others|website=Emscripten.org|publisher=Emscripten project|access-date=2021-02-10}}
While Emscripten and similar compilers allow writing new code, or porting extant code, written in a high-level programming language such as C, C++, Go, and Rust to WebAssembly to achieve potentially higher, native-level execution performance in web browsers, this forces web developers accustomed to developing client-side web scripts and applications in ECMAScript–JavaScript (the de facto client-side programming language in web browsers) to use a different language to target WebAssembly than JavaScript. AssemblyScript, as a variant of TypeScript that is syntactically similar to JavaScript, allows developers accustomed to JavaScript to use a familiar language to target WebAssembly, potentially reducing the learning curve of a separate language that can be compiled to WebAssembly. Also, because AssemblyScript was designed to be an optimal source language for WebAssembly, the language's type system closely reflects that of WebAssembly,{{cite web|url=https://www.assemblyscript.org/types.html|title=Types|author=|website=AssemblyScript.org|publisher=The AssemblyScript Project|access-date=2021-02-10}} and the language provides standard low-level functions (typically implemented as macros) that map directly to WebAssembly instructions that mirror instructions available on modern processors such as single instruction, multiple data (SIMD) and vector instructions and more specialized instructions such as clz
(count leading zero bits), ctz
(count trailing zero bits), and popcnt
(population count), used in applications such as encryption and cryptographic libraries.{{cite web|url=https://www.assemblyscript.org/environment.html|title=Environment|author=|website=AssemblyScript.org|publisher=The AssemblyScript Project|access-date=2012-02-10}}
{{mono|asc}}, the reference AssemblyScript compiler, is based on {{wdrl|Q131308722}}, a back-end compiler toolchain developed by Alon Zakai that compiles to WebAssembly and is a component of Emscripten (which Zakai also developed). The {{mono|asc}} compiler and other tooling are available via the npm package manager.
While WebAssembly was originally designed for execution within web browsers, the development of WASI (WebAssembly System Interface), a community specification for a standard API that allows WebAssembly programs access to system calls and other operating system functions,{{cite web|url=https://wasi.dev/|title=WASI: The WebAssembly System Interface|author=The Wasmtime Project|website=WASI.dev|publisher=The Wasmtime Project|access-date=2021-02-10}} has led to the development of WebAssembly runtime environments from projects such as {{wdrl|Q119398768}}{{cite web|url=https://wasmtime.dev/|title=Wasmtime: A small and efficient runtime for WebAssembly & WASI|author=The Wasmtime Project|website=Wasmtime.dev|publisher=The Wasmtime Project|access-date=2021-02-10}} and {{wdrl|Q105554548}}{{cite web|url=https://wasmer.io/|title=Wasmer: The Universal WebAssembly Runtime|author=Wasmer, Inc.|website=Wasmer.io|publisher=Wasmer, Inc.|access-date=2021-02-10}} that allow WebAssembly, and code written in languages such as AssemblyScript that can compile to it, to run in non-web environments as well.{{cite thesis|last1=Jaghori|first1=Sasan|date=1 August 2023|publisher=University of Applied Sciences Campus Vienna|title=Efficient Serverless Computing with WebAssembly|degree=Master|url=https://resolver.obvsg.at/urn:nbn:at:at-fhcw:1-104668}}
Compatibility with JavaScript
AssemblyScript is compiled to WebAssembly modules, which can then be instantiated into client-side Web pages using standard JavaScript methods such as WebAssembly.compileStreaming
and WebAssembly.instantiateStreaming
just like standard WebAssembly binaries.{{cite web|url=https://developer.mozilla.org/en-US/docs/WebAssembly/Loading_and_running|title=Loading and running WebAssembly code|author=Mozilla Developer Network|website=developer.mozilla.org|publisher=Mozilla Developer Network|access-date=2021-02-10}} Data passing between JavaScript and the compiled WebAssembly modules, as well as function calls between JavaScript and WebAssembly, are then the same as for any WebAssembly module.{{cite web|url=https://developer.mozilla.org/en-US/docs/WebAssembly/Using_the_JavaScript_API|title=Using the WebAssembly JavaScript API|author=Mozilla Developer Network|website=developer.mozilla.org|publisher=Mozilla Developer Network|access-date=2021-02-10}}
Because the AssemblyScript language is mostly a subset of TypeScript, it is theoretically possible to write an AssemblyScript program using this subset and compile it to both plain JavaScript and WebAssembly, using the TypeScript compiler and AssemblyScript compiler, respectively. This potentially allows portable code that can be used in either JavaScript or WebAssembly runtime systems (environments).
Use
{{As of|2025|05}}, more than 29,000 projects hosted on GitHub are written, either wholly or partly, in AssemblyScript,{{cite web|url=https://github.com/AssemblyScript/assemblyscript/network/dependents?package_id=UGFja2FnZS0xODY0NzM4NQ%3D%3D|title=AssemblyScript/assemblyscript Dependency graph|author=|website=GitHub.com|publisher=GitHub|access-date=2025-05-26}} with roughly 50,000 downloads of the AssemblyScript compiler per week via npm.{{cite web|url=https://www.npmjs.com/package/assemblyscript|title=assemblyscript Weekly Downloads|author=npmjs|website=npmjs.com|access-date=2025-05-26}}{{cite web| url=https://ittutoria.net/resolve-error-in-typescript-object-is-possibly-undefined/ |title= Resolve Error In Typescript |date= June 3, 2022 }} Saturday, 7 May 2022
In 2021, Webpack started using AssemblyScript to speed calculation of hash functions such as xxhash and md4 [https://github.com/webpack/webpack/tree/main/assembly/hash sources]. This also made it possible to remove native dependencies.
Reception
Lead Emscripten developer Alon Zakai has characterized AssemblyScript as being "designed with WebAssembly and code size in mind. It's not an existing language that we are using for a new purpose, but it's a language designed for WebAssembly. It has great wasm-opt
integration—in fact, it's built with it—and it's very easy to get good code size."{{cite web|url=https://www.youtube.com/watch?v=_lLqZR4ufSI|title=Shipping Tiny WebAssembly Builds|author=Alon Zakai|date=2020-02-19|website=YouTube.com|publisher=WebAssembly-Summit.org|access-date=2021-02-10}}
Norwegian musician Peter Salomonsen, in a 2020 WebAssembly Summit talk titled, "WebAssembly Music," demonstrated the use of AssemblyScript for real-time compiling to WebAssembly in live electronic music synthesis, saying, "I chose AssemblyScript because it has high-level readability and low-level control; it's like a high-level language, but you get that low-level feeling, and you can even write direct WebAssembly intrinsics if you want to."{{cite web|url=https://www.youtube.com/watch?v=C8j_ieOm4vE|title=WebAssembly Music|author=Peter Salomonsen|date=2020-02-19|website=YouTube.com|publisher=WebAssembly-Summit.org|access-date=2021-02-10}}
Aaron Turner, a senior engineer at Fastly, a cloud computing services provider that uses WebAssembly for the company's Compute@Edge serverless compute environment, in a review of AssemblyScript wrote:{{cite web|url=https://www.fastly.com/blog/meet-assemblyscript-your-next-computing-language|title=Meet AssemblyScript: your next computing language|author=Aaron Turner|date=2020-10-29|website=Fastly.com|publisher=Fastly|access-date=2021-02-10}}
While AssemblyScript requires stricter typing than TypeScript does, it sticks as close as possible to TypeScript syntax and semantics—which means that most JavaScript developers will find AssemblyScript comfortable to use—and it enables great support for the modern JavaScript ecosystem. For instance, the AssemblyScript compiler is available on {{mono|npm}}, as well as common AssemblyScript tools and libraries like {{mono|as-pect}}. AssemblyScript files also use TypeScript's ‘{{mono|.ts}}’ file extension, and it includes proper typings for allowing AssemblyScript to piggy-back on TypeScript tooling, such as the TypeScript linter. With the right small tweaks, AssemblyScript can even be used with the TypeScript compiler.
This is useful, as AssemblyScript offers a low-overhead entry-point for JavaScript developers to pick up a language to output WebAssembly—both in terms of learning to read and write AssemblyScript, and using much extant tooling that may already be in a JavaScript developer's workflow. AssemblyScript is often referred to in the WebAssembly community as a great gateway to picking up WebAssembly. It offers a large group of developers who already write applications for the web a path to pick up and learn WebAssembly. Even if you are starting from scratch and are not particularly familiar with JavaScript or TypeScript, AssemblyScript is a solid choice when picking a language to start outputting WebAssembly.
However, Turner went on to cite the language's relative newness and thus its lack of some features available in larger, more complex and established programming languages as potential but temporary shortcomings of the language.
See also
{{Portal|Free and open-source software}}
References
{{Reflist}}
External links
- {{Official website|www.assemblyscript.org}}
- {{GitHub|AssemblyScript}}
- [https://www.assemblyscript.org/introduction.html AssemblyScript documentation] (project page)
- [https://www.npmjs.com/package/assemblyscript assemblyscript] (on npm)
{{JavaScript}}
{{ECMAScript}}
{{Programming languages}}
Category:JavaScript programming language family
Category:Statically typed programming languages