Hello! I’m Aaron Turner, a senior software engineer on our Compute@Edge serverless compute environment, as well as a member of the AssemblyScript core team. We announced in our latest update to Compute@Edge that we’re supporting AssemblyScript — today, let’s take a deep dive into that fairly new language. Though it’s a bit ironic, I think the best way to start this discussion is with another language — JavaScript.
JavaScript is one of the most widely used programming languages. But it’s not always a perfect fit — like when you’re running logic at the edge. Downsides mostly revolve around JavaScript being a dynamically typed, interpreted language, meaning it requires a runtime to execute.
JavaScript runtimes must be heavily optimized and use techniques like Just-in-Time compilation to get JavaScript to perform at a level close to statically typed compiled languages in a best-case scenario at runtime. Runtimes like V8 do an amazing job at executing JavaScript using a reasonable amount of resources, but it would be more performant to not use a language that is dynamically typed or interpreted. What if we could have a similar developer experience to JavaScript but with the benefits of a statically typed compiled language?
TypeScript provides part of the answer by adding types to JavaScript, thereby, introducing type-safety to JavaScript applications. TypeScript is widely used among JavaScript developers: ~80% of JavaScript developers use, or want to learn, TypeScript. However, TypeScript doesn’t go the full distance toward compiled languages: it type-checks code but ultimately strips the types away to produce pure JavaScript rather than a fully-compiled binary.
Enter AssemblyScript
AssemblyScript is a variant of TypeScript that produces WebAssembly binaries, the binary format that powers Fastly’s Compute@Edge. WebAssembly is a new technology that is supported by all major browsers. Relative to JavaScript, WebAssembly offers predictable performance, making WebAssembly well suited for computationally intensive tasks. WebAssembly is also very portable, as it can be easily distributed in package registries like npm, and run in both the browser and standalone runtimes like Lucet.
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…