Quickly replace many blocks in a chunk

Discussion in 'Plugin Development' started by OLEGSHA, Dec 10, 2018.

Thread Status:
Not open for further replies.
  1. Offline

    OLEGSHA

    I plan to process chunks using the following scheme for the purposes of lag optimisation:
    1. Get chunk snapshot in main server thread
    2. Apply performance-intensive processing to snapshot using an auxiliary thread
    3. Dump results back into the chunk in main server thread
    Getting chunk snapshots is relatively easy to do (Chunk.getChunkSnapshot()) but there does not seem to exist a better way of applying changes to chunks than iterating over all Blocks. Is it possible to do it more efficiently? How high is the mean overhead when iterating over Blocks and changing their IDs and meta?

    Background: This is basically my attempt at performing computationally difficult chunk population so that chunk generation does not cause lag spikes. I assume that performing said population in main server thread would cause unwanted lag. I also assume that the chunk will not change during the work of my populator.

    Thank you in advance
    I will only be able to reply in about a day
     
  2. Offline

    MightyOne

    Well one thing that I did once for changing a lot of blocks was with a synchronously BukkitRunnable. Every tick I would change as many blocks as possible before 50ms (= the 1 tick) or a lower value passed. I guess it was working quiet lag free.
     
  3. @OLEGSHA

    If you want real speed, you could try to study the codes of WorldEdit, they are public (at least that's what I remember). However, I am not so good at reading, so I didn't find out how they do it...

    If you can't find it either, you can indeed go for the approach of the mighty one and spread the task over a longer time to avoid lagg. He measures how much time the task is taking, but you could also place a fixed amount of blocks per tick or let the admin configure the amount of blocks per tick to let it suit his needs.
     
  4. Offline

    MightyOne

    Actually I already managed it often enough to crash my private server with worldedit xD. I think this AsyncWorldedit might be a better example ti look at. Anyway, I also never managed to read their code
     
  5. Offline

    OLEGSHA

    I've been thinking about it and I have, too, come to this conclusion. I guess I'll use it as my last resort.

    I'll look it up. As @MightyOne said, WE can definitely crash servers, however, it does not mean that it does not employ a more optimised solution.

    Thank both of you for your answers. I'll write an update if I find anything significant.
     
Thread Status:
Not open for further replies.

Share This Page