Skip to content

Feature: AI Task Scan Throttle

Tsu edited this page May 31, 2026 · 1 revision

This feature controls how often AI scans for new tasks under load while still processing running tasks each tick.

Runtime Config

AiRuntimeConfig adds a dynamic scan interval:

public static float TaskScanIntervalSeconds = BaseTaskScanIntervalSeconds;

private const float BaseTaskScanIntervalSeconds = 0.2f;
private const float HighPlayerTaskScanIntervalSeconds = 0.3f;
private const float OverloadedTaskScanIntervalSeconds = 0.4f;
private const int HighPlayerThreshold = 150;
private const int OverloadedPlayerThreshold = 250;

Updated every 250ms based on online player count:

int onlinePlayerCount = serverApi?.World.AllOnlinePlayers.Length ?? 0;
TaskScanIntervalSeconds = onlinePlayerCount >= OverloadedPlayerThreshold
    ? OverloadedTaskScanIntervalSeconds
    : onlinePlayerCount >= HighPlayerThreshold
        ? HighPlayerTaskScanIntervalSeconds
        : BaseTaskScanIntervalSeconds;

Manager Flow

AiTaskManager.OnGameTick accumulates delta and only runs StartNewTasks() when the interval is reached.

startTaskAccum += dt;
if (startTaskAccum >= startTaskIntervalSeconds)
{
    startTaskAccum -= startTaskIntervalSeconds;
    ...
    StartNewTasks();
}

ProcessRunningTasks(dt);

Running tasks still continue each tick; the throttle is specifically on new-task scanning.

Timing Instrumentation

The patch also records timings for task scan and task continue paths through StratumEntityBehaviorTimings.

Related Files

  • patches/VSEssentials/Entity/AI/AiTaskManager.cs.patch
  • VSEssentials/Entity/AI/AiTaskManager.cs interval:
public static float TaskScanIntervalSeconds = BaseTaskScanIntervalSeconds;

private const float BaseTaskScanIntervalSeconds = 0.2f;
private const float HighPlayerTaskScanIntervalSeconds = 0.3f;
private const float OverloadedTaskScanIntervalSeconds = 0.4f;
private const int HighPlayerThreshold = 150;
private const int OverloadedPlayerThreshold = 250;

Updated every 250ms based on online player count:

int onlinePlayerCount = serverApi?.World.AllOnlinePlayers.Length ?? 0;
TaskScanIntervalSeconds = onlinePlayerCount >= OverloadedPlayerThreshold
    ? OverloadedTaskScanIntervalSeconds
    : onlinePlayerCount >= HighPlayerThreshold
        ? HighPlayerTaskScanIntervalSeconds
        : BaseTaskScanIntervalSeconds;

Manager Flow

AiTaskManager.OnGameTick accumulates delta and only runs StartNewTasks() when the interval is reached.

startTaskAccum += dt;
if (startTaskAccum >= startTaskIntervalSeconds)
{
    startTaskAccum -= startTaskIntervalSeconds;
    ...
    StartNewTasks();
}

ProcessRunningTasks(dt);

Running tasks still continue each tick; the throttle is specifically on new-task scanning.

Timing Instrumentation

The patch also records timings for task scan and task continue paths through StratumEntityBehaviorTimings.

Related Files

  • patches/VSEssentials/Entity/AI/AiTaskManager.cs.patch
  • VSEssentials/Entity/AI/AiTaskManager.cs

Clone this wiki locally