DEV Community

Cover image for Build a Chat service using GoLang and WebAssembly (part 1)
Taher Fattahi
Taher Fattahi

Posted on • Updated on

Build a Chat service using GoLang and WebAssembly (part 1)

concept 1

At the first I want to explain what is Webassembly?

in short, compile and run languages such as java-c#-python,.... into the browser we called Webassembly.

JavaScript has been the only programming language that the browser understands. JavaScript has stood the test of time and it has been able to deliver the performance needed by most web applications. But when it comes to 3D games, VR, AR, and image editing apps, JavaScript is not quite up to the mark since it is interpreted. Although JavaScript engines such as Gecko and V8 have Just in Time compilation capabilities, JavaScript is not able to provide the high performance required by modern web applications.

WebAssembly(also known as wasm) is meant to solve this problem. WebAssembly is a virtual assembly language for the browser. When we say virtual, it means that it cannot be run natively on the underlying hardware. Since the browser can be running on any architecture, it is not possible for the browser to run WebAssembly directly on the underlying hardware. But this highly optimized virtual assembly format can be processed much quicker than vanilla JavaScript by modern browsers since it is compiled and is more close to the hardware architecture than JavaScript. The following figure shows where WebAssembly stands in the stack when compared to Javascript. It is closer to the Hardware than JavaScript.

WebAssembly
The existing JavaScript engines have support to run WebAssembly's Virtual Assembly Code.

WebAssembly is not meant to replace JavaScript. It is meant to operate hand in hand with JavaScript to take care of performance critical components of a web application. It is possible to make calls from JavaScript to WebAssembly and vice versa.

WebAssembly is not generally coded by hand, but rather, it is cross compiled from other high level programming languages. For example, it is possible to cross compile Go, C, C++, and Rust code to WebAssembly. Thus the module which has already been coded in some other programming language can be cross compiled to WebAssembly and used in the browser directly.

Application of WebAssembly (WASM)

Where was WebAssembly supposed to be used at first? First of all, in tasks for processing heavy-duty tasks directly in the browser.

  • Game development
  • Video editing/streaming
  • Encryption
  • Image recognition

Concept 2


In part 2 we are going to write our first WebAssembly code with golang 😉

Top comments (4)

Collapse
 
sloan profile image
Sloan the DEV Moderator

Heyo!

This is an awesome post! 🔥

In fact, the topic of your post would also work really well in the Wasm Builders Community too!

Wasm Builders 🧱

Learn, connect, and showcase everything to do with WebAssembly; an emerging technology powering web, cloud, IOT, and more!

favicon wasm.builders

Wasm Builders is a global space for anyone interested in WebAssembly to learn, discuss, and share their creations with anyone in the community, and to foster an interest in this incredible technology. 🗣

Would you consider posting this article there too? Because Web Assembly is built on the same platform as DEV (Forem) you can fairly easily copy the Markdown and post your article there as well.

Really hope that you'll share your post with the community there and consider browsing the other Forem communities out there!

Collapse
 
taherfattahi profile image
Taher Fattahi

Hi,
Heyo :)))

thanks a lot for your consideration

ok, I have registered my account in wasm.builders, I will post this article in wasm.builders.

Thanks 🙏

Collapse
 
dnasedkina profile image
dnasedkina

waiting for part 2!

Collapse
 
taherfattahi profile image
Taher Fattahi • Edited

I try to publish every article every day,
you can see part 2.
Thanks 🙏