- [0] null
- [1] A1
NOPerf 0.1.0 · mechanism notes
How the NOPerf server optimizations work
The Spatial query
Sensors and weapons ask the battlefield grid which units are near a position. NOPerf.Spatial returns exactly the same list, in the same order. It just builds that list in one fewer pass.
The game divides the map into square cells. For a position and range, BattlefieldGrid.GetUnitsInRangeNonAlloc picks a rectangle of cells around the position. The shipped method first assembles the selected cells, then walks each cell's unit list from its last entry to its first, adding every entry to the caller's output list.
The optimized version uses the same rectangle and the same loops, but appends each unit as soon as it reaches it. No intermediate list of cells is built. Nothing is filtered by distance here: whatever the selected cells contain is returned, as before.
for (int x = x0; x < x1; x++) // x is the outer loop
for (int z = z0; z < z1; z++) // z is the inner loop
{
var source = gridLookup[z * divisions + x].units;
for (int i = source.Count - 1; i >= 0; i--) // last unit first
units.Add(source[i]);
}
In game-Mono method benchmarks this cut the method's time by about 28–33%. That is a method result. In an unoptimized hour of Escalation the query cost roughly 0.031 ms per game frame, and no whole-server speedup has been established.
Step through a query
A tiny made-up grid shows the order. Four cells, A to D, fall inside the selected rectangle. Cell C lists unit A1 a second time and also holds a null entry. The real grid can contain both, and both must survive.
Synthetic illustration · not game data · not a timing
Final state shown. Both outputs hold A2, A1, A1, null, B1, D2, D1. The full step list is below the figure.
Selected rectangle, 2 × 2 cells
- [0] D1
- [1] D2
- [0] A1
- [1] A2
- [0] B1
Original (shipped)
Pass 1: stage the selected cells.
- A
- C
- B
- D
Pass 2: walk each staged cell, last unit first.
NOPerf.Spatial (fused)
Visit the same cells and append directly. No staging list.
| Row | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|---|
| Original | A2 | A1 | A1 | null | B1 | D2 | D1 |
| Fused | A2 | A1 | A1 | null | B1 | D2 | D1 |
| Same? | = | = | = | = | = | = | = |
x outer, z inner, so A (x0 z0), C (x0 z1), B (x1 z0), D (x1 z1). Inside each cell the index runs from last to first. The only difference is the original's staging pass. The illustration shows that the pass is avoided, not how long it takes.All steps as text
- Original stages the selected cells A, C, B, D. Fused builds no staging list.
- Cell A (x0 z0), index 1: both outputs add A2 at position 0.
- Cell A, index 0: both add A1 at position 1.
- Cell C (x0 z1), index 1: both add A1 again at position 2. The duplicate is kept.
- Cell C, index 0: both add null at position 3. The null entry is kept.
- Cell B (x1 z0), index 0: both add B1 at position 4.
- Cell D (x1 z1), index 1: both add D2 at position 5.
- Cell D, index 0: both add D1 at position 6. The two outputs are identical: 7 entries in the same order.
What stays the same
- Cell rectangle. The same clamped centre cell, the same radius rounding and the same exclusive upper bounds. Changing coverage would change sensor and weapon decisions.
- Order.
xouter,zinner, units from last to first. - Contents. Duplicates and null entries pass through untouched. The output list is cleared first, as before.
- Fallbacks. Calls off the main thread, or before the grid exists, run the original method.
- Guard. The patch is applied only on the exact tested game assembly, only on a dedicated (batch-mode) server, and only if no other mod has already patched the method.
A runtime harness compared the patch against a Harmony reverse patch of the shipped method. It covered thousands of random, edge, fractional and non-finite queries, plus null-cell and null-output exceptions and Unity RNG state. See the validation chapter of the report.
Wrecks and Navigation
Both are experimental and disabled by default. Neither changes which wreck or route the game picks.
Wrecks: reusing a search snapshot
When a wreck collector looks for a wreck, the game copies its candidates into a new temporary list. During the outermost search on the main thread, NOPerf.Wrecks fills a list kept for that collector instead. The original selection code then runs over it unchanged. The list is cleared when the search ends, even if it throws, and is trimmed if it grows large. Nested searches, searches by another collector and off-thread calls still make a fresh copy.
Original
New list per search.
Wrecks plugin
One reused list per collector, emptied after each search.
The method benchmark improved by 0.9–3.5% at 128 candidates, with fewer GC collections. Empty searches added 0.006–0.65 µs. Whether it helps depends on the workload.
Navigation: road-node membership
Road pathfinding repeatedly asks whether a node is still in a list. A list answers that by scanning. On the first such check in a pathfinding call, NOPerf.Navigation builds a lookup indexed by node ID, with a count per node so duplicates behave as before. Removals still use the original list operation, so list order and sorting are untouched.
The plugin falls back to the original scan in these cases:
- IDs are negative, too large or too sparse, or two nodes share an ID.
- The list changes outside the patched calls.
- The call is nested or off the main thread.
Synthetic road graphs ran 6–13% faster. Pathfinding was sparse in the measured Escalation missions, so the effect on a whole server is unproven.
Limits
Method results are not server results. The percentages above come from method benchmarks. Mission comparisons stayed within run-to-run variation, and no FPS or capacity gain is claimed.
Vanilla clients are not live-tested. Clients install nothing, and static inspection found no new network messages, but unmodded join and rejoin were not tested.
One build only. On any other game assembly the plugins stay inactive. Each update needs a rebuild and fresh validation.
Install steps, configuration and build instructions are in the README. Measured results and charts are in the detailed test report.