Optimizations from server profile (#38290)

* Properly cache regexes in chat sanitization/accents

Wow I wonder if `new Regex()` has a cost to it *looks at server profile*.

* Avoid lag caused by Tippy command completions

CompletionHelper.PrototypeIDs explicitly says *not* to use it with EntityPrototype. Unsurprisingly, reporting a completion result for every entity prototype in the game is a *bad idea*.

* Add active count metrics to some high-load systems

Mover & NPCs

I suspect the thing that caused the Leviathan round to shit itself on performance is NPC spam in space or something. So let's verify that.

* Enable parallel processing on pow3r again

Originally disabled due to a theory of it causing bugs, it was re-enabled on Vulture, and I'm not aware of it having caused any issues there.

* Replace hashset with bitflags for AtmosMonitor alert types.

Allocating these hashsets was like 20% of the CPU of atmos, somehow.

* Cache HashSet used for space movement collider checks

Turns out this was a ton of server allocations. Huh.
This commit is contained in:
Pieter-Jan Briers
2025-07-26 11:44:34 +02:00
committed by GitHub
parent d0c104e4b0
commit 444180c20d
14 changed files with 217 additions and 128 deletions

View File

@@ -207,7 +207,7 @@ public sealed class AtmosMonitorSystem : EntitySystem
if (component.MonitorFire
&& component.LastAlarmState != AtmosAlarmType.Danger)
{
component.TrippedThresholds.Add(AtmosMonitorThresholdType.Temperature);
component.TrippedThresholds |= AtmosMonitorThresholdTypeFlags.Temperature;
Alert(uid, AtmosAlarmType.Danger, null, component); // technically???
}
@@ -218,7 +218,7 @@ public sealed class AtmosMonitorSystem : EntitySystem
&& component.TemperatureThreshold.CheckThreshold(args.Temperature, out var temperatureState)
&& temperatureState > component.LastAlarmState)
{
component.TrippedThresholds.Add(AtmosMonitorThresholdType.Temperature);
component.TrippedThresholds |= AtmosMonitorThresholdTypeFlags.Temperature;
Alert(uid, AtmosAlarmType.Danger, null, component);
}
}
@@ -259,7 +259,7 @@ public sealed class AtmosMonitorSystem : EntitySystem
if (!Resolve(uid, ref monitor)) return;
var state = AtmosAlarmType.Normal;
HashSet<AtmosMonitorThresholdType> alarmTypes = new(monitor.TrippedThresholds);
var alarmTypes = monitor.TrippedThresholds;
if (monitor.TemperatureThreshold != null
&& monitor.TemperatureThreshold.CheckThreshold(air.Temperature, out var temperatureState))
@@ -267,11 +267,11 @@ public sealed class AtmosMonitorSystem : EntitySystem
if (temperatureState > state)
{
state = temperatureState;
alarmTypes.Add(AtmosMonitorThresholdType.Temperature);
alarmTypes |= AtmosMonitorThresholdTypeFlags.Temperature;
}
else if (temperatureState == AtmosAlarmType.Normal)
{
alarmTypes.Remove(AtmosMonitorThresholdType.Temperature);
alarmTypes &= ~AtmosMonitorThresholdTypeFlags.Temperature;
}
}
@@ -282,11 +282,11 @@ public sealed class AtmosMonitorSystem : EntitySystem
if (pressureState > state)
{
state = pressureState;
alarmTypes.Add(AtmosMonitorThresholdType.Pressure);
alarmTypes |= AtmosMonitorThresholdTypeFlags.Pressure;
}
else if (pressureState == AtmosAlarmType.Normal)
{
alarmTypes.Remove(AtmosMonitorThresholdType.Pressure);
alarmTypes &= ~AtmosMonitorThresholdTypeFlags.Pressure;
}
}
@@ -306,17 +306,17 @@ public sealed class AtmosMonitorSystem : EntitySystem
if (tripped)
{
alarmTypes.Add(AtmosMonitorThresholdType.Gas);
alarmTypes |= AtmosMonitorThresholdTypeFlags.Gas;
}
else
{
alarmTypes.Remove(AtmosMonitorThresholdType.Gas);
alarmTypes &= ~AtmosMonitorThresholdTypeFlags.Gas;
}
}
// if the state of the current air doesn't match the last alarm state,
// we update the state
if (state != monitor.LastAlarmState || !alarmTypes.SetEquals(monitor.TrippedThresholds))
if (state != monitor.LastAlarmState || alarmTypes != monitor.TrippedThresholds)
{
Alert(uid, state, alarmTypes, monitor);
}
@@ -327,7 +327,7 @@ public sealed class AtmosMonitorSystem : EntitySystem
/// </summary>
/// <param name="state">The alarm state to set this monitor to.</param>
/// <param name="alarms">The alarms that caused this alarm state.</param>
public void Alert(EntityUid uid, AtmosAlarmType state, HashSet<AtmosMonitorThresholdType>? alarms = null, AtmosMonitorComponent? monitor = null)
public void Alert(EntityUid uid, AtmosAlarmType state, AtmosMonitorThresholdTypeFlags? alarms = null, AtmosMonitorComponent? monitor = null)
{
if (!Resolve(uid, ref monitor))
return;