cylc-ui icon indicating copy to clipboard operation
cylc-ui copied to clipboard

graph: investigate concurrency

Open oliver-sanders opened this issue 1 year ago • 3 comments

The Graphviz layout function is not async which suggests it's blocking.

The layout function is executing WASM under the hood and there are signs it might be using a worker pattern.

Does calling layout cause the entire UI to freeze or can other updates happen whilst this is going on?

If it is blocking we need to find a way of un-blocking it e.g: https://www.w3schools.com/HTML/html5_webworkers.asp

oliver-sanders avatar May 18 '23 12:05 oliver-sanders

I don't think it matters whether the layout code is async or not, it will still be blocking because JS is single threaded. I believe async/await/Promise is basically just fancy callbacks. See https://medium.com/docler-engineering/blocking-asynchronous-javascript-9416cdb65f59

According to that post, web workers would prevent the layout from being blocking, but I cannot figure out what @hpcc-js/wasm is actually doing.

(Note that for @hppc-js/wasm before v2 the layout method was async but the only async part was the Graphviz.load() which compiled the wasm. In v2 this part was split off into a different method leaving the layout method as a regular synchronous method.

MetRonnie avatar May 18 '23 14:05 MetRonnie

JS is single threaded, but web workers allow us to go beyond this running WASM and JS concurrently I think.

oliver-sanders avatar May 18 '23 14:05 oliver-sanders

After a quick exchange in person, the concern is that the layout call to the web worker (?) is not async so could potentially block unnecessarily while waiting for the web worker to execute

MetRonnie avatar May 18 '23 14:05 MetRonnie