How to run your web application and web workers in Super Dev Mode

A beautiful components library for GWT and JavaScript

How to run your web application and web workers in Super Dev Mode

June 13, 2018 Uncategorized 0

Web workers are a way to exploit the CPU's cores available. If you have a web application that requires a lot of computing power, it is a great way to tap an unexploited resource.

Web workers in Super Dev Mode on YouTube

You need to understand that all your JavaScript code, or Java code compiled by GWT, is single threaded. The browser executes everything you program when the main thread is available.

For example, setTimeout is only fake threading. If you have a computationally intensive piece of code, it impacts everything: asynchronous treatments, event handling, everything.

Hence, you should move the code that requires more CPU resources to web workers. Web Workers are effectively independent processes running in the browser.

The problem is there was so far no convenient way to do it with GWT.

If you have tried it before, you have found that you need to employ a custom linker to compile your web worker. However, if you do that, you cannot use Super Dev Mode, and you have to keep your web worker separated from the main application.

I decided to have a look at that because I needed to run an algorithm called Monte Carlo Tree Search; and as you guessed it uses the CPU a lot.

Fed up with the limitation of the standard "CrossSiteIframeLinker," the only linker that works in Super Dev Mode, I started playing with the JavaScript templates it uses.

Soon I was able to make it work.

Therefore, I could deploy both my main application and its web workers alongside, in Super Dev Mode.

I am attaching here two GWT 2.8.2 patched JARs so that you can play with it too!

And I will see how to integrate it directly to GWT.

The only thing that is not working yet is the source map of the web workers.

Anyway, to be able to use web workers efficiently in GWT is an invaluable addition, even more since Service Workers finally landed in Safari.

Patched GWT 2.8.2 JARs (gwt-codeserver.jar and get-dev.jar)

Web Worker Demo Eclipse Project

If you want to see what I did in the GWT source:
GWT source code patch

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.