Estecka/mc-Spawnproof-Villagers

[Question] about performance impact

Opened this issue · 5 comments

This mod looks a little complex.
Does it affect server performance in any way?
Does it constantly perform calculations that would otherwise not take place?

Every time the server attempts to spawn a mob, it will have to iterate over every entity in the world in order to find villagers. I haven't measured how much this iteration affects performance, but I think it should be minimal.

Beyond that, the calculations on each villager are limited to measuring its (squared) distance to the target spawn point; this is as similar as it can be to the Vanilla calculations that take place on every players.

The server attempts to spawn mobs on more or less every tick, so performing those calculations constantly is technically unavoidable.

"... it will have to iterate over every entity in the world in order to find villagers."
I suppose this reffers to only the loaded chunks right?
That's still a lot of entities, with limited server resources, it makes me worry a bit.

Yes of course.

Trying to include unloaded entities would honnestly be too absurd to even attempt. Completing a single iteration would require loading all chunks at least once, or to keep them loaded at all time. The performance cost of just that would not go unnoticed, regardless of the amount of entities.

That's still a lot of entities, with limited server resources, it makes me worry a bit.

To put things into perspective: On every tick, the base game has to iterate over all entities in order to update them. For each entity, it then has to iterate again over every other one in order to check for entity collisions.

Vanilla already does many such iterations per ticks, so each loop really must have a really negligible computation cost. These cases are just those I could come up with off the top of my head, there are probably more. Compared to that, this mod's iteration loop add little to the workload.

Thanks for the information, I'll try it out then, I suppose it can safely be removed in any case.