14

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

 2 years ago
source link: https://dev.to/taherfattahi/build-a-chat-service-using-golang-and-webassembly-part-1-1pee
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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 ๐Ÿ˜‰


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK