check_head_swivel is expensive when you have a lot of mobs near (e.g. cow farm) #3278

Open
opened 2023-01-07 15:48:34 +01:00 by ancientmarinerdev · 11 comments

MineClone2 version: Master

What happened?

Game gets laggy when you have a lot of mobs in a small area, such as a cow farm. They sprint from corner to corner. Profiler runs and I get 8.09% usage just on check_head_swivel. This is single player only. It could be even worse on multiplayer. This is a lot of performance impact for a superficial feature. We probably need to make this more performant.

What should happen:

Game shouldn't be laggy.

Steps to reproduce

Make a cow farm with about around 30 cows

MineClone2 version: Master ### What happened? Game gets laggy when you have a lot of mobs in a small area, such as a cow farm. They sprint from corner to corner. Profiler runs and I get 8.09% usage just on check_head_swivel. This is single player only. It could be even worse on multiplayer. This is a lot of performance impact for a superficial feature. We probably need to make this more performant. ### What should happen: Game shouldn't be laggy. ### Steps to reproduce Make a cow farm with about around 30 cows
ancientmarinerdev added the
bug
unconfirmed
labels 2023-01-07 15:48:34 +01:00
Author
Owner

Initial check suggest every on_step it checks for objects within a 10 block radius and then decides it should look or not look at them based on random chance. I'm going to pull the random chance out and see if we should even bother looking around first by checking random chance is successful first. If this doesn't help, I'll delve deeper.

Initial check suggest every on_step it checks for objects within a 10 block radius and then decides it should look or not look at them based on random chance. I'm going to pull the random chance out and see if we should even bother looking around first by checking random chance is successful first. If this doesn't help, I'll delve deeper.
Contributor

minecraft:gaze_cooldown_ticks: Optional. If the camel is in a cool down for randomly looking around.

value: The amount of ticks before the camel can randomly look around again and this tag is removed.

Minecraft has an Entity Format, where they store a lot of things, like gaze_cooldown_ticks. Maybe we should add a gaze cooldown too, and only look around when the cooldown is zero.

> minecraft:gaze_cooldown_ticks: Optional. If the camel is in a cool down for randomly looking around. > > value: The amount of ticks before the camel can randomly look around again and this tag is removed. Minecraft has an [Entity Format](https://minecraft.fandom.com/wiki/Entity_format#Entity_Format), where they store a lot of things, like `gaze_cooldown_ticks`. Maybe we should add a gaze cooldown too, and only look around when the cooldown is zero.
Author
Owner

That information is likely retrieved from looking at their code, so I won't be using that when designing a solution.

If it's talking about var names with a degree of confidence, we probably shouldn't consider this at all.

That information is likely retrieved from looking at their code, so I won't be using that when designing a solution. If it's talking about var names with a degree of confidence, we probably shouldn't consider this at all.
Contributor

All we need is to use the idea of a cooldown for mobs gazing at players, which is better than constantly+randomly determining if a mob should look around.

All we need is to use the idea of a cooldown for mobs gazing at players, which is better than constantly+randomly determining if a mob should look around.
ancientmarinerdev added
mobs
performance
and removed
unconfirmed
labels 2023-01-07 22:44:18 +01:00

A more ethical method would be for someone who owns MC to follow a cow around for example and keep following it while writing down how often it stops to look at you.

A more ethical method would be for someone who owns MC to follow a cow around for example and keep following it while writing down how often it stops to look at you.
Contributor

There's nothing unethical to use a simple idea as a cooldown. :) Besides, testing this in Minecraft would be a colossal waste of time, considering mobs gazing at players could be triggered and interfered by various factors.

There's nothing unethical to use a simple idea as a cooldown. :) Besides, testing this in Minecraft would be a colossal waste of time, considering mobs gazing at players could be triggered and interfered by various factors.
Author
Owner

I have reworked this a bit so it is less frequent and removed the checks that occur to earlier in the code to avoid wasteful searches of local thing: 02107971c95e33196ee305d17357d715a03ee508

There is still some way to go with this, but it went down locally from 8% to around 4%. It is worth revisiting but there is some complexity in the code and I went for the low hanging fruit.

I have reworked this a bit so it is less frequent and removed the checks that occur to earlier in the code to avoid wasteful searches of local thing: 02107971c95e33196ee305d17357d715a03ee508 There is still some way to go with this, but it went down locally from 8% to around 4%. It is worth revisiting but there is some complexity in the code and I went for the low hanging fruit.
Member

I was going to say.... When did ethics become part of this? And, how is the "less ethical method" less "ethical"?

I own MC, and there's no way in heck, you're going to get me to follow an in-game cow around unless I need steaks.

Besides, you trip up the random aspect mobs looking at you by being close and in their line of sight.

I was going to say.... *When did ethics become part of this?* And, how is the "less ethical method" less "ethical"? I own MC, and there's no way in heck, you're going to get me to follow an in-game cow around unless I need steaks. Besides, you trip up the random aspect mobs looking at you by being close and in their line of sight.
ancientmarinerdev removed the
bug
label 2023-01-09 02:38:44 +01:00

I was going to say.... When did ethics become part of this? And, how is the "less ethical method" less "ethical"?

I own MC, and there's no way in heck, you're going to get me to follow an in-game cow around unless I need steaks.

Besides, you trip up the random aspect mobs looking at you by being close and in their line of sight.

I was speaking in the context of ethical as in not looking at the java source code.

>I was going to say.... When did ethics become part of this? And, how is the "less ethical method" less "ethical"? >I own MC, and there's no way in heck, you're going to get me to follow an in-game cow around unless I need steaks. >Besides, you trip up the random aspect mobs looking at you by being close and in their line of sight. I was speaking in the context of ethical as in not looking at the java source code.
Contributor

Ok, but the wiki doesn't offer Java source code. They only code snippet that I know of, and I'm not sure it's directly copied from the source code, is the slime chunk formula.

Ok, but the wiki doesn't offer Java source code. They only code snippet that I know of, and I'm not sure it's directly copied from the source code, is the [slime chunk formula](https://minecraft.fandom.com/wiki/Slime#%22Slime_chunks%22).
Member

I was speaking in the context of ethical as in not looking at the java source code.

Ahh, okay. thank you for explaining. lol. (It was a head-scratcher for me)

> I was speaking in the context of ethical as in not looking at the java source code. Ahh, okay. thank you for explaining. lol. (It was a head-scratcher for me)
Sign in to join this conversation.
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: VoxeLibre/VoxeLibre#3278
No description provided.