OpenCubicChunks / CubicChunks2

Infinite* height mod for Minecraft - rewrite for versions above 1.12
MIT License
78 stars 19 forks source link

Investigate replacing CompletableFutures in chunk management with state maps #22

Open Cyclonit opened 4 years ago

Cyclonit commented 4 years ago

Problem Currently, tens of thousands CompletableFutures are being created during terrain generation. Terrain generation is split up into several stages (i.e. terrain, lighting, features, ...) When a cube is generated, other cubes in its neighbourhood are required to be at certain stages during their respective generation, such that all of the information for the requested cube to be generated is present.

In Vanilla 1.15. chains of CompletableFuture are used to represent these dependencies. Due to CubicChunks introducing the 3rd dimension, these chains grow to contain tens of thousands of CompletableFutures, hog up memory and slow down the system.

Possible Solution It might be possible to replace the entire CompletableFuture system with a map keeping track of the stage of each cube. ("HashMap<CubePos, StageTracker>"). The "StageTracker" is a small object containing a reference to the Cube's current stage and allow subscribers to listen for the cube reaching a given stage.

Barteks2x commented 4 years ago

Problem: you in the same cases you get a lot of completable futures now, a single StageTracker would need hundrreds to thousands of listeners (for all the neighbors in a given radius). Since there are also thousands of cubes... you are back to the same issue.