-
-
Notifications
You must be signed in to change notification settings - Fork 4
Feature: Entity Partition Reuse
Tsu edited this page May 31, 2026
·
1 revision
This feature keeps entity partitioning cheap under high entity counts by reusing partition structures across ticks.
Vanilla-style partition rebuild clears the dictionary each tick and recreates per-chunk/per-grid lists as entities are repartitioned.
Stratum keeps the partition dictionary and list instances, clears active chunks in-place, and only trims cold chunks occasionally.
From patches/VSEssentials/Systems/EntityPartitioning.cs.patch:
var activeChunks = stratumActiveChunks;
for (int i = 0; i < activeChunks.Count; i++)
{
var c = activeChunks[i];
var ents = c.Entities;
for (int g = 0; g < ents.Length; g++)
{
var list = ents[g];
if (list != null && list.Count > 0) list.Clear();
}
...
}
activeChunks.Clear();
int generation = ++stratumGeneration;The patch tracks whether a chunk was used this generation:
if (partition.StratumGeneration != generation)
{
partition.StratumGeneration = generation;
activeChunks.Add(partition);
}Instead of rebuilding every tick forever, Stratum trims unused chunks periodically:
private const int StratumTrimIntervalTicks = 300;
private const int StratumTrimChunkCountThreshold = 512;
private const int StratumTrimUnusedGenerations = 16;if (currentGeneration - kv.Value.StratumGeneration > StratumTrimUnusedGenerations)
{
(toRemove ??= new List<long>()).Add(kv.Key);
}The patch also clamps partition search expansion caused by oversized mod entities:
public static double StratumLargestTouchDistanceCap = 6.0;- less allocation churn per tick
- less GC pressure in crowded worlds
- stable partition behavior after large crowds disperse
patches/VSEssentials/Systems/EntityPartitioning.cs.patchVSEssentials/Systems/EntityPartitioning.cs