Git Product home page Git Product logo

Comments (1)

frpays avatar frpays commented on June 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.