CraftCanvasMC / Canvas

Empowering the impossible within Minecraft
https://canvasmc.io
55 stars 7 forks source link

Concurrent WorldThreading #22

Closed Dueris closed 3 months ago

Dueris commented 3 months ago

This PR merges the changes from the better world ticking branch which creates a better system to solve the bottleneck of the Server while not exploding lower end computers because of the amount of threads required. It also adds the following:

The main changes are as such:

In the previous code, world tick tasks were submitted to a ThreadPool to be completed async and then park the main thread until the tasks were done. Unfortunately, it only does so much. By continuing to have the tickrate locked down it only improved it by so much. The new method completely removes world ticking from the main thread and leaves only chunk ticking left.

Canvas, at startup, now creates new platform threads for each world to be ticked on independently, with its own TickRateManager - which is a class that defines important data for the tickrate - and scheduler, effectively making it its own main thread. This made performance SKYROCKET. Each world is now in charge of its own Entities, Block Entities, Players, BlockTicks, etc, while the main thread works on chunk ticks and other misc stuff like connection ticking(which I hope to be moved to the world tickers at some point). Lots of things were changed and fixed to make this possible, and there may be more bugs in the future, so for now canvas will be marked as unstable/experimental for the time being.