A First Look at WebAssembly - Gainer That Will Turn Browsers Into Power Lifters

What is WebAssembly

Evolution never stops. All things come into the world, grow and fade away in the end, letting other things take their place - that's the circle of life. Being a part of life, web browsers can't escape the same fate. It's time for them to grow and evolve.

Today we'll look at WebAssembly. It's a pretty interesting technology that can take web browsers to a new level. All of us get used to existing browser functions: texting, sending audio and video messages, music, videos, uploading and downloading files. But hey, how long we've been able to do this? 10 years? Maybe 15 years? That's pretty long period. We're living in the world of virtual reality, artificial intelligence, robots, flying skateboards and exo-suits. Browsers should fit this high-tech world!

WebAssembly tries to do that. Here's a short list of its features:

  • JavaScript augmentation: WebAssembly can take care of the most computationally intensive tasks and be imported as JS module;
  • Use your favourite back end language for front end: with WASM browser support, you can compile any language into the bytecode instead of JavaScript to use it all across the web;
  • Browsers upgrade: performance optimization and implementation of advanced technologies like 4k-graphics or desktop applications online. Let's have a detailed conversation about it with Michael Tsypkin, front end developer at Anadea.

Hi, Michael!
Hello.

Could you brief me what is WebAssembly?
Sure. It's a new way of how browser will work. JavaScript is the only thing you can run in browser for now. It means that no other language can run inside the browser. All you have to do is to convert those languages into JavaScript. For example, you can write in Scala and convert your code with ScalaJS into JavaScript afterwards.

And does WASM fix it?
Yes, but it takes the idea of its predecessors. Let's talk about computer science a bit. There're two categories of computer languages: compiling and interpreting ones. There are tons of compiling languages - C++ can be transformed into the assembler and then can be executed by processor. Assembler is the lowest level of processing. That's how compiling languages work. JavaScript is a kind of assembler for browsers. The major cons of it are low speed and numerous limitations of what you can do in browser.

The first solution of this problem was asm.js. It's an assembler adopted for JavaScript. To demonstrate its abilities, developers ran Unreal Engine 4 in Firefox browser. The performance was nearly twice slower than the UE4 itself. That's a great result because JavaScript is 16 times slower.

Wow!
Nevertheless, asm.js was a temporary solution. It was a kind of experiment. The idea of WebAssembly is to create permanent tool and set it as a standard in this area. WebAssembly is closer to machine code than asm.js, it's a binary file with its own format, in which you can reformat any programming language and run it in browser. So it's not a replacement of JavaScript. All web is written in JavaScript. If you remove it, the whole Internet will crash. WebAssembly is more like an augmentation - it gives possibility to write code in back end languages and run them in browser, that's it.

It seems like WASM has a really bright future!
It's hard to talk about the future of WASM because the technology is too young. It may open so many ways: maybe someone will create specific languages for browsers, maybe it'll improve performance and those back end languages will work faster than JavaScript. Who knows?

Does it work the same way as Java Virtual Machine?
It is. Browser is a virtual machine itself. JVM runs multiple languages: Java, Scala, Kotlin, etc. But the thing is, Java compiles into bytecode which is later interpreted by JVM. Write once, run in JVM everywhere, on any device - just like their slogan says.

Browser is like a virtual machine for JavaScript. Instead of bytecode, everything is compiled into JavaScript. With WebAssembly, the level of those languages scales down to the level of bytecode. Which means yes, there is a bit of JVM concept here.

Will it be easier to write code for front end developers?
Who knows? In the nearest future it won't affect front-ender's life at all. Much later, well, I believe WASM can start a trend of creating complex applications in browser. Maybe there will be some complex browser games. Not the same level as The Witcher 3, but they will be much better than what we have now. WASM can become really useful for VR technology in browser and things like that, it will be easier to develop them. So, it will influence the level of browser applications, but it won't impact the life of guys who write classic front end single page interfaces in React or Angular.

Also, I heard an idea that WebAssembly is the second breath for ChromeOS. Because now we can run more complex applications in browser and there is no limitations for this OS.

Any business potential?
I think, there will be a trend toward adapting desktop applications in browser. Photoshop, for example. Why not? I'm talking about its basic functions, not the whole functionality. At least, that's how I see it. There's also a theory that people would be able to write back end and front end with the same language. In Java, for example. Write server part in Java and some front end scripts. I'm a bit sceptical about it, because not all languages are good for this, but theory is theory.

Thanks for your time, Michael!
Anytime.

As you see, WebAssembly opens many ways for upgrading browsers. Accelerating their processing and adapting popular desktop applications looks like a next-gen browsers that we deserve. It also gives developers a possibility to improve performance of their applications and allows them to develop more complex and more productive software. We'll see how things go after its release and we can't wait for it quietly, as we're too excited about it. Hope you enjoyed this first look. Keep on reading Anadea Blog for more interestiing news and information from the world of software development.

Get in Touch