Skip to content

Commit

Permalink
Slightly reduce memory turnover by using a locally allocated list for…
Browse files Browse the repository at this point in the history
… the fast group prober. Another attempt to make "Delay" priority work, but the pathing needs to actually be executed before the next chore is chosen...
  • Loading branch information
peterhaneve committed Jan 4, 2025
1 parent b582fd4 commit 71c9211
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion FastTrack/FastTrack.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyTitle>Fast Track</AssemblyTitle>
<FileVersion>0.15.3.0</FileVersion>
<FileVersion>0.15.4.0</FileVersion>
<RootNamespace>PeterHan.FastTrack</RootNamespace>
<Description>Optimizes Oxygen Not Included to improve performance.</Description>
<AssemblyVersion>0.15.0.0</AssemblyVersion>
Expand Down
4 changes: 3 additions & 1 deletion FastTrack/PathPatches/AsyncPathPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ internal void UpdateBrainGroup(AsyncBrainGroupUpdater inst, bool asyncProbe,
handled.Clear();
switch (priorityMode) {
case FastTrackOptions.NextChorePriority.Delay:
// Add priority brains to the delay list and wait until reachability pops
// Add priority brains to the delay list
// Chicken and egg problem: Need to update the brain to get a pathing
// update, but not drop the chore
if (gp != null) {
reachability = gp.UpdateCount;
if (reachability == lastReachability)
Expand Down
17 changes: 12 additions & 5 deletions FastTrack/SensorPatches/FastGroupProber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ internal static void Init() {
/// The cells which were marked dirty during path probes.
/// </summary>
private readonly ConcurrentQueue<int> dirtyCells;

/// <summary>
/// The temporary list of cells that became dirty this update.
/// </summary>
private readonly IList<int> dirtyTemp;

/// <summary>
/// The cells which were marked dirty during path probes.
Expand Down Expand Up @@ -129,6 +134,7 @@ private FastGroupProber() {
cells = new int[Grid.CellCount];
destroyed = false;
dirtyCells = new ConcurrentQueue<int>();
dirtyTemp = new List<int>(32);
Mask = new ThreadsafePartitionerLayer("Path Updates", Grid.WidthInCells, Grid.
HeightInCells);
probers = new ConcurrentDictionary<object, ReachableCells>(2, 64);
Expand Down Expand Up @@ -285,7 +291,6 @@ private void ProcessLoop() {
d = destroyed;
if (!d && hit)
Process();
Interlocked.Increment(ref updateCount);
} while (!d);
// Clean up the object for real
probers.Clear();
Expand All @@ -310,11 +315,13 @@ internal void Remove(object prober) {
/// </summary>
internal void Update() {
// Trigger partitioner updates on the foreground thread
var dirtyList = ListPool<int, FastGroupProber>.Allocate();
while (dirtyCells.TryDequeue(out int cell))
dirtyList.Add(cell);
Mask.Trigger(dirtyList, this);
dirtyList.Recycle();
dirtyTemp.Add(cell);
if (dirtyTemp.Count > 0) {
Mask.Trigger(dirtyTemp, this);
dirtyTemp.Clear();
}
Interlocked.Increment(ref updateCount);
int n = toDo.Count;
if (n > 0 && FastTrackMod.GameRunning) {
if (n > MIN_PROCESS)
Expand Down

0 comments on commit 71c9211

Please sign in to comment.