Fire control 12.4 fix batch F5: measure the steady state, not the first window
LaneAndSilhouetteAllocateNothingGivenAPooledBuffer failed in 1 of 12 full-suite runs (1232 bytes over 1000 Lane calls) and in 0 of 100 runs of the test alone or its class. The allocation is a one-off, not a per-call cost: under suite load the runtime's background tier-up is delayed by other tests' JIT activity, so first-use allocation lands inside the single measured window. The rule stays: Lane and buffered Silhouette allocate nothing. The test now measures up to 20 rounds of 1000 calls and requires the smallest round to be zero. A per-call allocation appears in every round and still fails it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
76e98598b1
commit
fd79201358
1 changed files with 22 additions and 9 deletions
|
|
@ -1352,22 +1352,35 @@ public sealed class FireControlCut12Tests : IDisposable
|
|||
for (var i = 0; i < 100; i++) FireControl.Lane(hull, bearing, sil.A, laneBuffer); // JIT warm-up
|
||||
for (var i = 0; i < 100; i++) FireControl.Silhouette(e.Target, hull, null, bearing, .5f, intervalBuffer);
|
||||
|
||||
var before = GC.GetAllocatedBytesForCurrentThread();
|
||||
for (var i = 0; i < 1000; i++) FireControl.Lane(hull, bearing, sil.A, laneBuffer);
|
||||
var laneAllocated = GC.GetAllocatedBytesForCurrentThread() - before;
|
||||
Assert.True(laneAllocated == 0, $"1000 Lane calls allocated {laneAllocated} bytes; \"never allocates\" is not true");
|
||||
// Steady state, not first-use: under a whole-suite run the runtime's background tier-up is delayed by the
|
||||
// other tests' JIT activity, so a one-off allocation (measured: 1232 bytes over 1000 calls, in 1 of 12
|
||||
// full-suite runs and 0 of 100 isolated runs) can land inside a single window. That is a cost paid once.
|
||||
// A per-call allocation, the regression this test guards, lands in EVERY round, so the smallest round
|
||||
// over a bounded number of rounds is the steady-state allocation.
|
||||
long SmallestRoundAllocation(Action round)
|
||||
{
|
||||
var smallest = long.MaxValue;
|
||||
for (var r = 0; r < 20 && smallest != 0; r++)
|
||||
{
|
||||
var start = GC.GetAllocatedBytesForCurrentThread();
|
||||
round();
|
||||
smallest = Math.Min(smallest, GC.GetAllocatedBytesForCurrentThread() - start);
|
||||
}
|
||||
return smallest;
|
||||
}
|
||||
|
||||
before = GC.GetAllocatedBytesForCurrentThread();
|
||||
for (var i = 0; i < 1000; i++) FireControl.Silhouette(e.Target, hull, null, bearing, .5f, intervalBuffer);
|
||||
var silhouetteAllocated = GC.GetAllocatedBytesForCurrentThread() - before;
|
||||
Assert.True(silhouetteAllocated == 0, $"1000 buffered Silhouette calls allocated {silhouetteAllocated} bytes");
|
||||
var laneAllocated = SmallestRoundAllocation(() => { for (var i = 0; i < 1000; i++) FireControl.Lane(hull, bearing, sil.A, laneBuffer); });
|
||||
Assert.True(laneAllocated == 0, $"1000 Lane calls allocated {laneAllocated} bytes in every round; \"never allocates\" is not true");
|
||||
|
||||
var silhouetteAllocated = SmallestRoundAllocation(() => { for (var i = 0; i < 1000; i++) FireControl.Silhouette(e.Target, hull, null, bearing, .5f, intervalBuffer); });
|
||||
Assert.True(silhouetteAllocated == 0, $"1000 buffered Silhouette calls allocated {silhouetteAllocated} bytes in every round");
|
||||
|
||||
// Recorded, not asserted zero: the full gated-in HitProbability call still allocates, from Entity's own
|
||||
// collection enumeration (GetBehavior<T> over ReactiveCollection<T>), not from anything this fix batch
|
||||
// touches. A loose upper bound catches a real regression (e.g. a reintroduced comparer wrapper) without
|
||||
// pretending Entity's own cost is Lane's or Silhouette's to fix here.
|
||||
for (var i = 0; i < 100; i++) FireControl.HitProbability(e.Weapon, e.Shooter, e.Target);
|
||||
before = GC.GetAllocatedBytesForCurrentThread();
|
||||
var before = GC.GetAllocatedBytesForCurrentThread();
|
||||
var sum = 0f;
|
||||
for (var i = 0; i < 1000; i++) sum += FireControl.HitProbability(e.Weapon, e.Shooter, e.Target);
|
||||
var hitProbabilityAllocated = GC.GetAllocatedBytesForCurrentThread() - before;
|
||||
|
|
|
|||
Loading…
Reference in a new issue