kangarko / Boss

Premium custom monsters plugin with skill system, natural spawning and lots of sickest features!
https://www.mc-market.org/resources/21619/
77 stars 28 forks source link

Causing Lag Always, 1.12.2 Paper #1198

Closed SladeHazard closed 1 year ago

SladeHazard commented 1 year ago

Boss is always at the top of my timings and spark report, can this please be optimized or any steps on improving it?

image

SladeHazard commented 1 year ago

this is only with 1 player online, i think it's higher with 200+

kangarko commented 1 year ago

We have to unfortunately call Bukkit to find what block is at a given location which appears to be slow. This might be because the overall server performance is impacted by something else so Bukkit takes longer to get block at a location.

Post me full spark profiler URL with your 200 players please.

SladeHazard commented 1 year ago

We have to unfortunately call Bukkit to find what block is at a given location which appears to be slow. This might be because the overall server performance is impacted by something else so Bukkit takes longer to get block at a location.

Post me full spark profiler URL with your 200 players please.

can I know what location.getblock is being used for? because I can probably optimize it for my own server's use-case. or if you're able to a disable option, delay or something. As this plugin is always at the top, even though I have 150+ plugins all properly optimized

chatgpt: Optimize Algorithms: Check the method findSuitableOffsetLocation(). Are you calling Location.getBlock() multiple times for the same location? If so, cache the result. Also, see if you can reduce the number of calls to this method. Maybe you don't need to calculate the block for every location every time.

SladeHazard commented 1 year ago

image image

SladeHazard commented 1 year ago

I'd be fine with using the same spawn positions if this is because of a random spawn algorithm

kangarko commented 1 year ago

Here is the full method in case you decompiled and it got altered:

private Location findSuitableOffsetLocation(Location clone) {

        for (int i = 0; i < 15; i++) {
            final int randomXoffset = RandomUtil.nextBetween(-8, +8);
            final int randomYoffset = RandomUtil.nextBetween(-2, +2);
            final int randomZoffset = RandomUtil.nextBetween(-8, +8);

            final Location newLocation = clone.clone().add(randomXoffset, randomYoffset, randomZoffset);
            final Block newBlock = newLocation.getBlock();
            final Block above = newBlock.getRelative(BlockFace.UP);

            if (CompMaterial.isAir(newBlock) && CompMaterial.isAir(above))
                return newLocation;
        }

        return clone;
    }

So what we do for this spawn rule is to make the spawning seem more natural by moving the boss around a bit around the spawn location. Obviously there might be blocks unfit for the spawn such as lava or blocks suffocating the mob, so we have to get the block including the one above since most mobs are 2-block tall, and check if both are air.

We could cache this data, but it would produce bad results if a player places or removes a block around the boss and we do not check it freshly.

To disable this completely, disable Location Offset in the spawn rule settings:

a

kangarko commented 1 year ago

I have added the warning to GUI, thanks for informing me.

SladeHazard commented 1 year ago

in that case a better alternative would be to let people define multiple positions themselves rather than randomizing it but I guess that's already possible so I will just disable it, thank you

fyi it shows in timings too as this is done on the main thread

kangarko commented 1 year ago

Right, you can define multiple positions manually.

If timings is still an issue please send another spark report with that option disabled. Would be best if you send the entire URL, if you want to send in private just email us at support@mineacademy.org with said URL