More Random Code Optimizations (#2339)

These are all essentially just random systems that scaled directly with
player count (or were on my list of the top 50 anyways). So just a
couple systems that had very inefficient enumerators being swapped out
with significantly more efficient ones, plus a few swaps from O(n) to
O(m) m << n. A big one was DrainSystem, which was querrying all possible
entities, rather than doing so from the "set of all static objects",
which is significantly smaller. Puddles are always static objects, so it
doesn't make sense to have the drains check for anything other than
static.

We can also use DirtyField to save on performance costs of Dirty(uid,
component) in cases where the Dirty is only networking a single
component field.

no CL this isn't player facing.
This commit is contained in:
VMSolidus
2025-05-20 20:44:05 -04:00
committed by Spatison
parent efd0b66036
commit 7dc84aaae4
11 changed files with 79 additions and 67 deletions

View File

@@ -9,9 +9,7 @@ using Content.Shared.Temperature;
using Content.Shared.Verbs;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Player;
using Robust.Shared.Utility;
namespace Content.Server.Light.EntitySystems
@@ -37,9 +35,15 @@ namespace Content.Server.Light.EntitySystems
public override void Update(float frameTime)
{
var query = EntityQueryEnumerator<ExpendableLightComponent>();
while (query.MoveNext(out var uid, out var light))
var query = EntityQueryEnumerator<ActiveExpendableLightComponent>();
while (query.MoveNext(out var uid, out var _))
{
if (!TryComp(uid, out ExpendableLightComponent? light))
{
RemCompDeferred<ActiveExpendableLightComponent>(uid);
continue;
}
UpdateLight((uid, light), frameTime);
}
}
@@ -47,9 +51,6 @@ namespace Content.Server.Light.EntitySystems
private void UpdateLight(Entity<ExpendableLightComponent> ent, float frameTime)
{
var component = ent.Comp;
if (!component.Activated)
return;
component.StateExpiryTime -= frameTime;
if (component.StateExpiryTime <= 0f)
@@ -81,6 +82,7 @@ namespace Content.Server.Light.EntitySystems
_item.SetHeldPrefix(ent, "unlit", component: item);
}
RemCompDeferred<ActiveExpendableLightComponent>(ent);
break;
}
}
@@ -99,7 +101,7 @@ namespace Content.Server.Light.EntitySystems
_item.SetHeldPrefix(ent, "lit", component: item);
}
var isHotEvent = new IsHotEvent() {IsHot = true};
var isHotEvent = new IsHotEvent() { IsHot = true };
RaiseLocalEvent(ent, isHotEvent);
component.CurrentState = ExpendableLightState.Lit;
@@ -107,7 +109,7 @@ namespace Content.Server.Light.EntitySystems
UpdateSounds(ent);
UpdateVisualizer(ent);
EnsureComp<ActiveExpendableLightComponent>(ent);
return true;
}
@@ -134,7 +136,7 @@ namespace Content.Server.Light.EntitySystems
case ExpendableLightState.Dead:
_appearance.SetData(ent, ExpendableLightVisuals.Behavior, string.Empty, appearance);
var isHotEvent = new IsHotEvent() {IsHot = true};
var isHotEvent = new IsHotEvent() { IsHot = true };
RaiseLocalEvent(ent, isHotEvent);
break;
}