fabric-chunkpregenerator icon indicating copy to clipboard operation
fabric-chunkpregenerator copied to clipboard

Avoid generating chunks beyond 100% and some performance improvements

Open TelepathicGrunt opened this issue 6 months ago • 1 comments

The batch enqueueing was queueing up chunks but not checking how many to queue up before it would hit 100%. As a result, users can see at times when the progress bar shows over 100% due to lingering extra chunks that were queued up.

The fix here it a bit checking heavy. Might be a way to simplify it. But it does solve the issue at hand!

Current pregenerator code that can go beyond 100%:

https://github.com/jaskarth/fabric-chunkpregenerator/assets/40846040/503e637c-037d-4dda-a4e4-3cf296d90730

With the fix implemented:

https://github.com/jaskarth/fabric-chunkpregenerator/assets/40846040/d91576bd-2f56-4524-b95f-be6337f4f972

TelepathicGrunt avatar Dec 10 '23 23:12 TelepathicGrunt

Last improvement I swear! This is using the getChunkIoWorker().scanChunk method you recommended earlier to me. This will verify if the chunk at a position is fully generated or not. If not, the chunk will be loaded and generated. If it is already fully made, it will be skipped and not loaded into memory. I decided to do this during the pregen process instead of before because the existing generated chunks could be in any pattern in world (not just a square centered on player) and wanted to avoid any startup lag before generation kicks off.

Here's a video of a speed boost for how fast it skips over a pregenerated 32 chunk radius:

https://github.com/jaskarth/fabric-chunkpregenerator/assets/40846040/b79cbb8d-e08f-4793-9c28-ce3f0dd59063

Video of the old speed for comparison and all these chunks were loaded into memory and their POI taking up RAM forever despite the chunks unloading after pregen (the POI loading into memory is a memory leak that affects vanilla but only noticeable when loading a huge number of chunks. So any chunk we can skip loading is a boon for us):

https://github.com/jaskarth/fabric-chunkpregenerator/assets/40846040/d953f72c-fae7-4d0b-85ad-be93ab42bc40

Video showing that pregen skips over the chunks and generates new chunks properly with new way (going from radius 24 to radius 26):

https://github.com/jaskarth/fabric-chunkpregenerator/assets/40846040/07801f36-249d-4cb1-a77e-5df8a97bce9d

If this change is a bit much to have, lmk and I'll revert it out of this PR. Hopefully this is good!

TelepathicGrunt avatar Dec 12 '23 18:12 TelepathicGrunt