Engineering

WebAssembly For High Performing Industrial And Medical Use Cases

Web applications are becoming increasingly resource-intensive. Use cases such as web-based image/video editing, image recognition, live video augmentation, and more can be taxing on server hardware. Moreover, important applications in the medical and industrial fields are becoming increasingly necessary in today’s digital landscape.

WebAssembly solves the problem of acquiring enterprise-grade server hardware by allowing web applications to run at near-native speed regardless of how computationally demanding a task might be. WebAssembly is a means to allow scripts written in C/C++, Rust, C#, and more to run on web browsers. In that way, the power and speed of scripts written in these languages are able to be leveraged on modern web browsers.

What Is WebAssembly?

WebAssembly is an assembly-like language that is designed to run on modern web browsers. It consists of machine-code instructions and is compatible with modern web browsers. Additionally, it is designed to run alongside JavaScript.

It enables developers to use traditionally non-web languages such as C/C++, Rust, and C# by providing a compilation target so that they can run on the web. The advantage of using WebAssembly is that it allows web applications to run at near-native speed.

It is currently being developed as a web standard by the W3C WebAssembly Working Group and Community Group. It is currently ubiquitous as Mozilla has already declared support in all major browsers. As of January 2021, 93% of browsers support WebAssembly.

Goals

1. Be Fast, Efficient, and Portable:

As mentioned earlier, WebAssembly can be executed at near-native speed.

2. Be Readable and Debuggable:

Though it is assembly-like, it still has to be articulate enough for humans to read, understand, and debug.

3. Keep Secure:

It is meant to be executed in a sandbox environment and to enforce standard security procedures such as same-origin and permissions policies.

4. Don’t Break the Web:

It has to be compatible with all web technologies.

Common Use Cases

Here are the intended use cases for WebAssembly. It can be divided into internal and external use cases. The former pertains to its use within the browser whereas the latter pertains to its use outside the browser.

Internal Use Cases:
  1. Better execution for languages (C/C++, GWT, etc.) and toolkits that are currently cross-compiled to the Web
  2. Image/video editing
  3. Games
  4. Peer-to-peer applications
  5. Music applications
  6. Image recognition
  7. Live video augmentation
  8. VR and augmented reality
  9. CAD applications
  10. Scientific visualization and simulation
  11. Interactive educational software, and news articles
  12. Platform simulation/emulation (ARC, DOSBox, QEMU, MAME, …)
  13. Language interpreters and virtual machines
  14. POSIX user-space environment, allowing porting of existing POSIX applications
  15. Developer tooling
  16. Remote desktop
  17. VPN
  18. Encryption
  19. Local webserver
  20. Common NPAPI users, within the web’s security model and APIs
  21. Fat client for enterprise applications (e.g. databases)

External Use Cases
  1. Game distribution service
  2. Server-side compute of untrusted code
  3. Server-side application
  4. Hybrid native apps on mobile devices
  5. Symmetric computations across multiple nodes

How Does WebAssembly Work?

Taken from https://blog.logrocket.com/webassembly-how-and-why-559b7f96cd71/

The web application will have a virtual machine that hosts and runs the code and a set of web APIs that can be used to control the app’s functionality. A number of things can be performed by web APIs such as DOM, CSSOM, WebGL, IndexedDB, web audio API, and more.

What happens is that code is written in a certain language like JavaScript and compiled into WebAssembly. The virtual machine runs that .wasm binary code that emulates functions at near-native speed.

Traditionally, virtual machines are only able to load JavaScript. Because of JavaScript’s flexibility and utility, it has been a non-issue up until more intensive applications like 3D games, virtual/augmented reality, computer vision, image/video editing, and more started being more in-demand.

WebAssembly answers the question of how to run intensive web applications efficiently while maintaining portability, ease-of-integration, and backward compatibility.

Key Concepts

These are the components of a WebAssembly Javascript API script. JavaScript code can call exported WebAssembly functions and run them as if they were JavaScript functions. In the future, WebAssembly modules will be loaded just like ES2015 modules for easy compilation and usage.

1. Module

A stateless, blob-like binary that has been compiled into executable machine code.

2. Memory

An ArrayBuffer that contains the bytes being read and written by the low-level memory access instructions.

3. Table

An array of references to functions.

4. Instance

A module paired with all the states it uses at runtime (memory, table, and imported values).

Limitations

1. WebAssembly cannot directly interact with DOM. Instead, JavaScript interoperability needs to be used for this.

2. Currently, there is no multithreading

3. Currently, there is no garbage collection

4. There are security considerations regarding the usage of WebAssembly to bypass browser security for Spectre and Meltdown attacks once multithreading and shared memory are added.

Porting From C/C++

A tool called Emscripten is one of the many available online wasm assemblers. Other tools include WasmFiddle, WasmFiddle++, and WasmExplorer. These tools can take any C/C++ code and promptly compile them into a .wasm module.

After which, simply use JavaScript to load, run, and display the module. Since as mentioned earlier, WebAssembly cannot directly access DOM, the JavaScript glue code acts as a mediator.

Using Blazor To Build Client Apps With C#

Microsoft’s Blazor is a wasm assembler that allows users to write web applications using C#. It is a feature of ASP.NET. It can either run client-side code directly in the browser or on the server. If it is run on the server, the UI events are sent back to the client and merged to the DOM after server-side processing.

It is built upon open web standards and works on all modern browsers. If the code is run directly on the browser, it is run within a security sandbox just like JavaScript frameworks. Otherwise, if it is run on the browser, users will be able to connect directly to the database.

Writing WebAssembly Directly

It is possible to write your own compiler. You take a text file and convert it to binary format with a WebAssembly text-to-binary tool. An example program would be WABT or WebAssembly Binary Toolkit. What this does is it takes a text file that has been converted to a wat file simply by virtue of file extension. After which, translates the .wat file into .wasm.

Web-Based HMI

An HMI or a Human Machine Interface is commonly used to control and monitor machines. An example of an HMI would be the ATM machine wherein the screen and buttons allow you to communicate with the machine to dispense money.

In industrial applications, HMIs are important because it enables automated processes with human supervision. The HMI could include important information such as temperature, pressure, process steps, material counts, and more.

Now, web-based HMI simply uses the browser as an interface as opposed to a physical machine. It hosts several benefits such as increased operator awareness, ease of development, deployment, and maintenance, and fast response time.

Web-based HMIs are said to reduce development time by up to 40%. Users define their structured asset model and map it to the SCADA database. Users save time because of predefined mappings that cover most use cases.

Using WebAssembly for HMIs ensures that information is updated and displayed at near-native speeds which is important for sensitive operations such as in power plants, electricity facilities, and more.

Web-Based Enterprise-Grade Medical Image Decoder

In medicine, a DICOM or a Digital Imaging and Communications in Medicine is the standard protocol and file format for the usage of medical images online. Some examples of medical images include MRI images, patient information, and ultrasound images. The format makes sure that all information is intact while in transit.

Since browsers do not natively recognize DICOM images, WebAssembly can be used to decode DICOM images at near-native speed. Traditionally, healthcare web applications would handle this by having the server transcode the image into an uncompressed image format.

The caveat here is that the server would need to have powerful hardware to support DICOM image decoding at scale. Another alternative would be to decode the images in the browser using JavaScript. This works in general however it does not support all JPEG2000 features. JPEG2000 is one of the image compression formats for DICOM.

Finally, using WebAssembly to write a decoder that includes support for JPEG-LS and JPEG2000 is the most efficient way to solve the problem. The idea is to use the needed C/C++ libraries and compile the decoder into WebAssembly. Using WebAssembly to decode DICOM images on the fly is faster, more efficient, and less computationally expensive than traditional methods.

Get Expert Help In WebAssembly

Here at Codvo.ai, we believe that web applications should be blazingly fast without the cost of maintaining enterprise-grade hardware. With WebAssembly, we can achieve near-native speed on demanding web applications. If your company needs a web-based HMI or web-based enterprise-grade medical image decoder, our subject matter experts can handle the matter with ease and precision. Additionally, costs for enterprise-grade hardware will be nonexistent.
If you are interested in WebAssembly, contact us today at marketing@codvo.ai !

You may also like