WebAssembly Basics

WebAssembly is essential to the blockchain technology project DFINITY that I am involved in. In today’s episode, I talk about the basics of WebAssembly and why it’s important.

Video Transcript

Alright, we just finished our morning workout. We went for a run and some calisthenics. We’re having showers and after that, we’re headed for breakfast. Probably start our first work session at the breakfast.

What I like to do at these retreats when we get together is first to get an idea of everyone’s expectations and lay out what we’re going to approach within the next few days so that we’re all on the same page and we all have a good idea of what we want to achieve.

By the way, my shoulder is already almost back to normal. Pretty amazing how quickly the human body heals.

Exciting new project with unexciting Wi-Fi

It’s about 1:00 p.m. and we’ve been working on our schedule for the next few days. Working on a very exciting new project, putting all the pieces together of what we want to achieve in the next few days and which goals we want to reach.

Today is a holiday here in Turkey. Just quickly going to venture out for lunch. Also, see if we can find better Wi-Fi because the place that we’re staying at has okay-ish Wi-Fi but it’s probably not going to be good enough for longer calls.

***

So we found a cafe that had pretty good Wi-Fi but not really private rooms so we’re going to look for a co-working space tomorrow. Probably just roam from or tethered from a phone today.

What is WebAssembly?

So when you hear of DFINITY, one of the keywords that you’re often going to hear about is WebAssembly or short WASM.

WebAssembly is a standard that’s been developed by the major browser manufacturers such as Microsoft with Microsoft Edge, Google with Google Chrome, Apple with Safari, and Mozilla with Firefox.

They invented WASM over the last few years. And what WASM is – it’s basically a binary or it’s a bytecode that can be executed in browsers.

If you’ve ever worked on web projects or web applications you know that typically the way it works that the language the browser is able to interpret are HTML, CSS, and JavaScript. Those are the three major languages that your browser is able to interpret and then render your website or web application.

These languages are great and very high level, it’s very easy to get started but they also have a few downsides. One of them being that it’s very inefficient to compile code at runtime every single time you execute it. One thing that you’ve might have noticed when using your browser – there are a lot of applications that seemingly are “pretty simple” if you compare them with your desktop applications but still consume a lot of resources in your browser.

So people have been looking for ways to make it more efficient to run web applications, especially more complicated and resource-heavy applications. And WebAssembly is one way that they’re trying to use to solve that problem.

By sending bytecode to the browser’s virtual machine, the browser has to do a lot less computation in order to execute it and it’s a lot more efficient to execute those instructions.

Compiling code to get WebAssembly

Also, another benefit of WebAssembly is that there can be compilers from a variety of languages that then compile the logic into WebAssembly. You could be writing your code in C or Haskell or Rust or Go and then use that code, compile it and get WebAssembly on the other end.

So unlike JavaScript or HTML or CSS where you need to know these exact languages, you could now understand one of a variety of languages and just use a compiler to get to WebAssembly. Of course, you could also develop in WebAssembly directly but WebAssembly is a very low-level language meaning there’s a lot of overhead and it can potentially be very tedious and take a lot of time to even write and accomplish simple tasks if you’re writing in WebAssembly instructions directly.

To illustrate what that means, here are a few examples of how the same program or the same logic looks in different languages. First, here’s the example in JavaScript.

In JavaScript, it takes you just a few lines in order to define a string and then print it out letter by letter into the browser.

Here’s the same example, this time written in C which is a lower level language than JavaScript and it takes you four lines of code to do the same thing. You define a string and then you print it character by character. Only in this case, it’s more common to print C code into a console or your terminal instead of the web browser.

And last but not least, here’s the same logic – an application that does nothing but print the two words “Hello Sendtask” in WebAssembly. And you’ll see that instead of using three or four lines of code, it uses roughly ten times as many lines of code.

Dinner at “The Butcher”

7:30 p.m. – leaving the house for dinner. Where are we headed, Bojan?

To Kasabim.

To Kasabim – steakhouse. For everyone who knows Turkish, that means butcher.

This guy parked in the middle of the road in a way that I guess cars could still go by but I’m still unsure if it was intentional or if it was an accident.

Kasabim – the steakhouse that we’re going to and apparently it’s been here since the 1950s.

Headed back to the apartment to talk a bit more about blockchain and DFINITY. And then it’s probably time for some sleep soon as well.

So with that, let’s have a good night and I’ll talk to you tomorrow!


You can listen to the audio version here:

Comments


Cédric Waldburger

Cédric Waldburger

Founder of Sendtask.io 🚀. I'm passionate about startups 👨‍🚀. I live out of a carry-on 💼. I own 64 things. They're all black.

Get tips & advice on essentialism delivered straight to your inbox