Pressure plates need to be more performant #3600

Open
opened 2023-03-28 20:18:26 +02:00 by ancientmarinerdev · 13 comments

MineClone2 version: master

What happened?

Pressure plates are quite expensive. When you have a few around, they can take 4% and locally, it was at 9.21%.

I think this is because the timer runs every 0.4 seconds, and it searches for players close by. I understand why we functionally do this and had some real issues with plates thinking they were pressed. What I am wondering is if we can change the distance searched, or the interval so it is less frequent.

I don't know if there is a reason it is 0.04, or could be higher say 0.2, or 0.25, or 0.5. It probably bare minimum needs to work for the minimum time a pressure plate is affected. This could reduce load by 75-80% potentially.

I have no idea what the best way to approach this is. @MrRar do you have any ideas, as you seem to be our resident pressure plate expert.

What should happen:

Pressure plates should work less frequently, but still function effectively.

Steps to reproduce

When profiling with pressure plates close by.

MineClone2 version: master ### What happened? Pressure plates are quite expensive. When you have a few around, they can take 4% and locally, it was at 9.21%. I think this is because the timer runs every 0.4 seconds, and it searches for players close by. I understand why we functionally do this and had some real issues with plates thinking they were pressed. What I am wondering is if we can change the distance searched, or the interval so it is less frequent. I don't know if there is a reason it is 0.04, or could be higher say 0.2, or 0.25, or 0.5. It probably bare minimum needs to work for the minimum time a pressure plate is affected. This could reduce load by 75-80% potentially. I have no idea what the best way to approach this is. @MrRar do you have any ideas, as you seem to be our resident pressure plate expert. ### What should happen: Pressure plates should work less frequently, but still function effectively. ### Steps to reproduce When profiling with pressure plates close by.
ancientmarinerdev added the
bug
unconfirmed
labels 2023-03-28 20:18:26 +02:00
ancientmarinerdev added
nodes
performance
#P3: elevated
and removed
unconfirmed
labels 2023-03-28 20:19:41 +02:00
Contributor

Some pressure plates also need to be triggered when items fall on them. Would it be a good trade-off for items landing on something to check if they fell on a pressure plate? The complicated(?) part here is that light/heavy weighted pressure plates need to be triggered based on how many entities/items are on them.

In the case of mobs and players, would collision checking with pressure plates be more expensive?

Some pressure plates also need to be triggered when items fall on them. Would it be a good trade-off for items landing on something to check if they fell on a pressure plate? The complicated(?) part here is that light/heavy weighted pressure plates need to be triggered based on how many entities/items are on them. In the case of mobs and players, would collision checking with pressure plates be more expensive?
Member

not to mention we are still missing 2 pressure plates left if there was a better way to implement them in heavy and light weighted pressure plates

not to mention we are still missing 2 pressure plates left if there was a better way to implement them in heavy and light weighted pressure plates
Member

I think any performance improvement will have to involve reducing the timer. However this will make it more likely that an object can pass over the pressure plate without triggering it. But there might be a way to optimize it without losing much functionality. For example, the pressure plates could have a slow timer most of the time but if they detect a moving entity nearby they could decrease the timer for the next server tick.

I will have to experiment.

I think any performance improvement will have to involve reducing the timer. However this will make it more likely that an object can pass over the pressure plate without triggering it. But there might be a way to optimize it without losing much functionality. For example, the pressure plates could have a slow timer most of the time but if they detect a moving entity nearby they could decrease the timer for the next server tick. I will have to experiment.
MrRar self-assigned this 2023-03-29 16:07:16 +02:00
Member

I'm at a loss right now about how to test the performance of the pressure plates.
I had a world with 1024 pressure plates.

First I tried using jitprofile. I tried different values for the node timer. Below is the results. The first number is the node timer. The second number is the execution time percentage for pressure plates.
0.04: 21%
0.2: 22%
0.5: 31%
2: 18%
As you can see it's basically random. I think this might be because it's a percentage and not an absolute time. So whatever happens to be going on the world will have as much of an impact as the pressure plates themselves.

Next I tried Minetest's built-in profiler. But the pressure plates did not show up at all under that as far as I can tell.

Then I tried Minetest's built in time functions minetest.get_gametime() and minetest.get_us_time() but apparently they only update between server ticks.

I will see if there is anything else to try.

If anyone has any suggestions, that would be great.

I'm at a loss right now about how to test the performance of the pressure plates. I had a world with 1024 pressure plates. First I tried using jitprofile. I tried different values for the node timer. Below is the results. The first number is the node timer. The second number is the execution time percentage for pressure plates. 0.04: 21% 0.2: 22% 0.5: 31% 2: 18% As you can see it's basically random. I think this might be because it's a percentage and not an absolute time. So whatever happens to be going on the world will have as much of an impact as the pressure plates themselves. Next I tried Minetest's built-in profiler. But the pressure plates did not show up at all under that as far as I can tell. Then I tried Minetest's built in time functions minetest.get_gametime() and minetest.get_us_time() but apparently they only update between server ticks. I will see if there is anything else to try. If anyone has any suggestions, that would be great.
Author
Owner

What was taking up the performance? Was maploading happening at same time?

I may only have a handful of pressure plates and they should up, so this is weird.

What was taking up the performance? Was maploading happening at same time? I may only have a handful of pressure plates and they should up, so this is weird.
Author
Owner

I think any performance improvement will have to involve reducing the timer. However this will make it more likely that an object can pass over the pressure plate without triggering it. But there might be a way to optimize it without losing much functionality. For example, the pressure plates could have a slow timer most of the time but if they detect a moving entity nearby they could decrease the timer for the next server tick.

I will have to experiment.

How much will we lose. 0.04 seconds is 25 times a second. Even if it's 5 times a second, it should cover almost all cases. I cannot think of anything 0.25s, I cannot see a situation in which it not triggering would be a big deal.

The performance issue as I see it is far too frequent looking around. Looking for nodes or entities near by is very cpu intensive.

> I think any performance improvement will have to involve reducing the timer. However this will make it more likely that an object can pass over the pressure plate without triggering it. But there might be a way to optimize it without losing much functionality. For example, the pressure plates could have a slow timer most of the time but if they detect a moving entity nearby they could decrease the timer for the next server tick. > > I will have to experiment. > How much will we lose. 0.04 seconds is 25 times a second. Even if it's 5 times a second, it should cover almost all cases. I cannot think of anything 0.25s, I cannot see a situation in which it not triggering would be a big deal. The performance issue as I see it is far too frequent looking around. Looking for nodes or entities near by is very cpu intensive.
Member

Was maploading happening at same time?

I will post the SVG files I made tomorrow.

0.04 seconds is 25 times a second.

Default server tick is 0.09 so that would allow 11 times a second at the most. The node timer never runs more than one time per node per tick.

Even if it's 5 times a second, it should cover almost all cases. I cannot think of anything 0.25s, I cannot see a situation in which it not triggering would be a big deal.

It's good to have them as reliable as possible. I think the timer can be increased without losing much reliability. Reliability can be tested. But I can't test the performance. Maybe increasing the timer has no substantial impact on performance for some reason. Since I don't have any data you might just have to increase the timer and hope for the best.

> Was maploading happening at same time? I will post the SVG files I made tomorrow. > 0.04 seconds is 25 times a second. Default server tick is 0.09 so that would allow 11 times a second at the most. The node timer never runs more than one time per node per tick. > Even if it's 5 times a second, it should cover almost all cases. I cannot think of anything 0.25s, I cannot see a situation in which it not triggering would be a big deal. It's good to have them as reliable as possible. I think the timer can be increased without losing much reliability. Reliability can be tested. But I can't test the performance. Maybe increasing the timer has no substantial impact on performance for some reason. Since I don't have any data you might just have to increase the timer and hope for the best.
Author
Owner

Was maploading happening at same time?

I will post the SVG files I made tomorrow.

0.04 seconds is 25 times a second.

Default server tick is 0.09 so that would allow 11 times a second at the most. The node timer never runs more than one time per node per tick.

local PRESSURE_PLATE_INTERVAL = 0.04

Even if it's 5 times a second, it should cover almost all cases. I cannot think of anything 0.25s, I cannot see a situation in which it not triggering would be a big deal.

It's good to have them as reliable as possible. I think the timer can be increased without losing much reliability. Reliability can be tested. But I can't test the performance. Maybe increasing the timer has no substantial impact on performance for some reason. Since I don't have any data you might just have to increase the timer and hope for the best.

I'm happy with that, I just didn't know if increasing timer meant I had to change other times too. I don't know how the total times are stored or calculated.

> > Was maploading happening at same time? > > I will post the SVG files I made tomorrow. > > > > 0.04 seconds is 25 times a second. > > Default server tick is 0.09 so that would allow 11 times a second at the most. The node timer never runs more than one time per node per tick. local PRESSURE_PLATE_INTERVAL = 0.04 > > Even if it's 5 times a second, it should cover almost all cases. I cannot think of anything 0.25s, I cannot see a situation in which it not triggering would be a big deal. > > It's good to have them as reliable as possible. I think the timer can be increased without losing much reliability. Reliability can be tested. But I can't test the performance. Maybe increasing the timer has no substantial impact on performance for some reason. Since I don't have any data you might just have to increase the timer and hope for the best. I'm happy with that, I just didn't know if increasing timer meant I had to change other times too. I don't know how the total times are stored or calculated.
Member

local PRESSURE_PLATE_INTERVAL = 0.04

I acknowledge the timer is 0.04. But I assert that it actually can't run more frequently than the server tick which is 0.09 by default.

> local PRESSURE_PLATE_INTERVAL = 0.04 I acknowledge the timer is 0.04. But I assert that it actually can't run more frequently than the server tick which is 0.09 by default.
Member

I'm happy with that, I just didn't know if increasing timer meant I had to change other times too. I don't know how the total times are stored or calculated.

Just change PRESSURE_PLATE_INTERVAL and your good.

> I'm happy with that, I just didn't know if increasing timer meant I had to change other times too. I don't know how the total times are stored or calculated. Just change PRESSURE_PLATE_INTERVAL and your good.
Member

I have attached the SVG files a made using jitprofiler

I have attached the SVG files a made using jitprofiler
ancientmarinerdev added
#P2: HIGH
and removed
#P3: elevated
labels 2023-03-31 17:02:02 +02:00
Author
Owner

I have attached the SVG files a made using jitprofiler

That is some weird results? I would have expected different (higher time bringing lower effect). How about 30 or so plates? Any more than probably won't happen frequently.

> I have attached the SVG files a made using jitprofiler That is some weird results? I would have expected different (higher time bringing lower effect). How about 30 or so plates? Any more than probably won't happen frequently.
Member

I have attached the SVG files a made using jitprofiler

That is some weird results? I would have expected different (higher time bringing lower effect). How about 30 or so plates? Any more than probably won't happen frequently.

I tried 9 and it did not show up on the SVG at all. Then I tried 49 plates. I have attached the SVG files. No pattern to it.

> > I have attached the SVG files a made using jitprofiler > > That is some weird results? I would have expected different (higher time bringing lower effect). How about 30 or so plates? Any more than probably won't happen frequently. I tried 9 and it did not show up on the SVG at all. Then I tried 49 plates. I have attached the SVG files. No pattern to it.
ancientmarinerdev added this to the 0.83.0 - Safe and Sound milestone 2023-04-04 21:07:13 +02:00
Ghost modified the milestone from 0.83.0 - Safe and Sound to 0.84.0 - Very Nice 2023-04-15 22:50:40 +02:00
ancientmarinerdev added
#P3: elevated
and removed
#P2: HIGH
labels 2023-04-16 23:29:20 +02:00
ancientmarinerdev modified the milestone from 0.84.0 - Very Nice to 3 - Near future 2023-04-16 23:29:24 +02:00
ancientmarinerdev added
#P4 priority: medium
and removed
#P3: elevated
labels 2023-04-17 20:51:52 +02:00
ancientmarinerdev added the
#Review
label 2023-05-09 16:30:53 +02:00
ancientmarinerdev removed this from the 3 - Near future milestone 2023-05-09 16:42:29 +02:00
teknomunk added this to the Redstone Update project 2024-11-29 12:40:16 +01:00
Sign in to join this conversation.
No Milestone
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#3600
No description provided.