Comments (1)
Hey,
Thanks for bringing up this issue, and sorry with the delay. Maybe you moved on, but that's an interesting issue to comment on, so I will gladly do anyway.
There are two distinct code paths.
let useWebWorker = 'undefined' != typeof OffscreenCanvas;
If we detect a usable javascript Worker with a working Offscreen canvas implementation, then we create a Worker where lc0 will run asynchronously with respect to the user interface. The javascript Worker will have its own dedicated thread, and the main javascript thread hosting the user interface will communicate with the worker using non blocking postmessage()
, receiving the bestmove with onmessage()
. As a result, the user interface is reasonably smooth.
If we cannot detect a Worker, then we create a LC0Worker class instance that mimics the Worker interface (postmessage()
and onmessage()
looks the same). As a result the rest of the code is pretty much identical. But the crucial difference is the engine is no longer asynchronous. In the use case of go/bestmove, postmessage()
does not returns before the onmessage() is called. As a result, the user interface is frozen when the engine computes the best move. These are 'degraded mode' conditions.
The Worker is the recommended way to interact with lc0 asynchronously. It will work out-of-the-box on Chrome. You will have to enable the offscreen canvas on Firefox. Sadly, on some browsers, it won't work at all.
How can you make lc0 works asynchronously without javascript Worker and Offscreen canvas?
I am afraid you cannot. The async
keyword is syntactic sugar for premises and won't create any particular thread context. The lc0 engine is compiled with Emscripten without thread support, so the user interface and lc0 share the same thread. When you call Step() on the engine, the user interface has to be frozen.
Note that the user-interface is really frozen during the call to Step()
which in return call RunOneIteration()
on the engine. The user-interface actually "breathes" between calls and process messages (mouse move or press), but the results nonetheless looks "jerky".
from lc0-js.
Related Issues (2)
- lc0 network HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lc0-js.