Closed BaronyCraft closed 5 years ago
Cool, thanks for the contribution. Sounds good.
I'll try to make some time in the next few days to review this for inclusion.
Apologies on the delay. Finally had a chance to check through the code a bit more thoroughly and do at least a bit of testing of Fill in Paper and in standard Spigot.
Couldn't see much in the way of performance differences from running and re-running a Fill in a VM in the background on the same world after trimming it, but saw no problems introduced. If nothing else (ignoring potential general Fill speed improvements like you saw) I can imagine it will very likely help with running Fill on a live server with players.
Seems good, thanks for the contribution.
I'll be making a beta release shortly to let a wider range of people test it out more thoroughly, just to be on the safe side, before declaring a stable release.
This uses PaperLib to handle async chunk generation; it will use sync or async generation depending on the abilities of the underlying server.
Because there may be several ticks between the request to load/generate a chunk and the time when the chunk is actually there, the server might decide it doesn't need the freshly loaded chunk and unload it again. To prevent this, the FillTask keeps a list of chunks that are needed, and which other chunk they're needed for, and a ChunkUnloadEvent listener prevents unloading of chunks while they're on the list.
In order to not fill the async generate queue faster than it can generate them, every tick checks how many chunk loads/generations have been performed in the last tick and how full the queue is, and fills the queue to just slightly more entries than it will probably be able to perform until the next tick.
This logic works as well when using a Server that can't generate chunks asynchronously; in that case, there won't be any pending chunks left at the start of a new tick. Chunks will still be generated in one tick, and the generation result evaluated in the next one.
I ran some tests with Spigot 1.13.2 / Paper 1.13.2, with this implementation and the official WorldBorder 1.9.0., by setting a square border of +/- 1000 and running /wb fill 1000. Without users on a server, this implementation is slightly faster on Paper, but not much:
However, when joined the server in creative mode, and flew around the border while the generation task was running, Spigot TPS dropped to 15, while Paper TPS remained at 19.7, and it was very visible that Paper kept up with generating all chunks around the player, while Spigot had noticable lag.