JaimeGensler / thyseus

An archetypal Entity Component System, built entirely in Typescript
MIT License
74 stars 3 forks source link

[HELP] Does multithreading work in nodejs side? #53

Closed linonetwo closed 1 year ago

linonetwo commented 1 year ago

What do you need help with?

I'm planning to use thyseus with colyseus, which only run game logic in server side.

I'm not sure if thyseus can use worker_thread of nodejs, because in the doc it says

Parallelism is enabled by taking advantage of technologies offered by modern browsers

Target Environment

Node

JaimeGensler commented 1 year ago

Hi there - thanks for your question & interest in Thyseus! 🙏

Unfortunately, threading will not work for Node right now, as it depends on the Worker global being available. In the meantime, I believe Bun has the Worker global and is (supposed to be) a drop-in replacement for Node, but if you're more comfortable sticking with Node that's entirely fair - I haven't tried Bun yet myself.

As a general note, Thyseus' concurrency model will be getting a complete overhaul at some point in the future, and one of the explicit goals of this redesign is to be useable in Node. I'll be posting more information about that soon, and tracking progress in an issue - I'll link it here once I've got it set up. For transparency, I don't have a timeline for this change right now.

Cheers!

linonetwo commented 1 year ago

Thanks, I have experience with https://github.com/andywer/threads-plugin , but it is a webpack plugin, not a rollup plugin.

I will try bun to see if it works out-of-box. And I think when using in the server, multi-threading is not that necessary, because there will be many game rooms, occupy all the CPU cores... So I just need to ensure the ecs running on the client side is multi-threading is enough!