MZ Multithread on MZ?

Is multithreading possible on MZ? If yes, can you give me a simple code or link me to a tutorial? Thanks.
It is possible, but no, we cannot give you a simple code. MZ is made to be single-threaded, which complicates pretty much everything. https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers
You could also use Worker Threads form Node Link. But yeah following what Poryg says, this would only be useful if you are developing a plugin that uses intense processing.
If I remember it correctly VorbisDecoder in MZ uses workers (and uses also web assembly) and it is on it's own thread.
It is possible, but no, we cannot give you a simple code. MZ is made to be single-threaded, which complicates pretty much everything. https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers
Will pathfinding findDirectionTo() work on web workers?
You could also use Worker Threads form Node Link. But yeah following what Poryg says, this would only be useful if you are developing a plugin that uses intense processing.
Does pathfinding 30 events at the same time intense processing? I still haven't tested my game on mobile phones but I feel like it will lag.
Yeah using webworker and offscreencanvas https://en.wikipedia.org/wiki/Web_worker

I also saw implementation of webworker when creating navmesh in babylon.js. But i am not sure in MZ tho https://doc.babylonjs.com/extensions/crowdNavigation/createNavMesh
Will pathfinding findDirectionTo() work on web workers?

Does pathfinding 30 events at the same time intense processing? I still haven't tested my game on mobile phones but I feel like it will lag.
like this ? for example : https://yuka.babylonpress.org/examples/js/navigation/navmeshPerformance/ ? well this demo work perfectly in browser so i guess it's fine to do in MZ
If you edit it appropriately, it will. However, there are caveats to it.

In order to solve the problem of multiple threads potentially writing into one variable, workers do not have access to any variables from any other web workers or the main thread. This means that you cannot access your events from a web worker.
Any communication between web workers and the main thread happens through postMessage and onMessage events. You'd have to send the map to the worker as well as the events and other obstacles.
If you edit it appropriately, it will. However, there are caveats to it.

In order to solve the problem of multiple threads potentially writing into one variable, workers do not have access to any variables from any other web workers or the main thread. This means that you cannot access your events from a web worker.
Any communication between web workers and the main thread happens through postMessage and onMessage events. You'd have to send the map to the worker as well as the events and other obstacles.
That will probably make my code complicated. Thanks though!
If you edit it appropriately, it will. However, there are caveats to it.

In order to solve the problem of multiple threads potentially writing into one variable, workers do not have access to any variables from any other web workers or the main thread. This means that you cannot access your events from a web worker.
Any communication between web workers and the main thread happens through postMessage and onMessage events. You'd have to send the map to the worker as well as the events and other obstacles.
yeah, that is true, by the way i hear some people said worker can't access DOM by default so you need to use offscreencanvas. https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas
Do you know what it's actually means for MZ context ?
yeah, that is true, by the way i hear some people said worker can't access DOM by default so you need to use offscreencanvas. https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas
Do you know what it's actually means for MZ context ?
I want to know this too.
@Neptrone DOM is indeed inaccessible by workers, however that's not all.
Global variables are inaccessible as well. Each worker thread has its own global context. So you cannot use window._foo in a worker thread. Neither can you use thread1._foo in thread 2.
And the same is true for the MZ context. It's only accessible from the main thread. If you want to do shenanigans with them on worker threads, you need to copy them there or edit the scripts so that these variables are created on worker threads, not on main thread.

Web workers are essentially an attempt to make Javascript multithreaded, but the fact that workers don't share memory at all really limits their usefulness.
@Neptrone DOM is indeed inaccessible by workers, however that's not all.
Global variables are inaccessible as well. Each worker thread has its own global context. So you cannot use window._foo in a worker thread. Neither can you use thread1._foo in thread 2.
And the same is true for the MZ context. It's only accessible from the main thread. If you want to do shenanigans with them on worker threads, you need to copy them there or edit the scripts so that these variables are created on worker threads, not on main thread.

Web workers are essentially an attempt to make Javascript multithreaded, but the fact that workers don't share memory at all really limits their usefulness.
how about using shared array buffer ? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer ?
Correct. Not even SharedArrayBuffer. Had you read it well, you'd see that SharedArrayBuffer can be shared in the postMessage function, but this sharing creates a private instance of the ArrayBuffer for both of the threads. It's only called SharedArrayBuffer, because normal ArrayBuffer cannot be sent through the postMessage function - only a string can.
It seems to be possible with SharedBufferArray and Atomic objects, look at this article.

This also should be possible with Node implementation of worker threads and it's preferred as it's more cleaner. Though doing any of this will require a lot of work and may not be as plug and play as you might hoped it to be.

As for the performance of the game you can check that with chrome and it's "Device emulation" in the web developer console. Also throttle the cpu.
It seems to be possible with SharedBufferArray and Atomic objects, look at this article.

This also should be possible with Note implementation of worker threads and it's preferred as it's more cleaner. Though doing any of this will require a lot of work and may not be as plug and play as you might hoped it to be.

As for the performance of the game you can check that with chrome and it's "Device emulation" in the web developer console. Also throttle the cpu.
Interesting. Also recent proposal of new javascript features (ES2022) there are proposal called In-Place Resizable and Growable ArrayBuffers (which allows us to have better memory management) https://github.com/tc39/proposal-resizablearraybuffer
It seems to be possible with SharedBufferArray and Atomic objects, look at this article.

This also should be possible with Note implementation of worker threads and it's preferred as it's more cleaner. Though doing any of this will require a lot of work and may not be as plug and play as you might hoped it to be.

As for the performance of the game you can check that with chrome and it's "Device emulation" in the web developer console. Also throttle the cpu.
Are event and map functions possible through it?
Interesting. Also recent proposal of new javascript features (ES2022) there are proposal called In-Place Resizable and Growable ArrayBuffers (which allows us to have better memory management) https://github.com/tc39/proposal-resizablearraybuffer
Will the upcoming rpg maker unite use C#?
Are event and map functions possible through it?
Theoretically, yes, but as I said, it requires a lot of work, reading the documentation of how worker threads work, and a good understanding of Rpg Maker javascript code.
Will the upcoming rpg maker unite use C#?
For that there is a separate thread discussing it. In short it's a sort of "layer" for Unity so, yes it uses C#

Original thread: https://forums.rpgmakerweb.com/threads/multithread-on-mz.147545/