refactor(teleport A): O(N) deferred drain + never-arrives test (review fixes)

Replace RemoveAt(0)-in-a-loop drain idiom with RemoveRange(0, i) in both
Step-1 deferred drain and the post-found deferred drain inside DrainAndApply,
making each an O(N) single shift instead of O(N²) on the render-thread hot path.

Add PriorityNeverArrives_noThrow_noLoss_noDoubleApply test: sets a priority id
that never appears in the outbox, ticks several times, asserts no throw, no
loss of the non-priority completions, and no double-apply (applied count ==
completions enqueued). Comment above the priority-hunt explains the failure
mode: completions relocate to _deferredApply while the hunt is active and drain
at per-frame budget until the caller clears PriorityLandblockId.

Restyle test 2 to use named constructor arguments and break the compressed
lambda onto readable lines (matches test 1 style).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-06-22 13:03:20 +02:00
parent 1f6baa6cfc
commit f918b3ea2c
2 changed files with 75 additions and 20 deletions

View file

@ -336,15 +336,10 @@ public sealed class StreamingController
// --- Step 1: drain the deferred buffer first (items held from a prior
// priority-hunt that overshot the cap). Apply up to `budget` of them.
int deferredApplied = 0;
while (deferredApplied < budget && _deferredApply.Count > 0)
{
var item = _deferredApply[0];
_deferredApply.RemoveAt(0);
ApplyResult(item);
deferredApplied++;
}
budget -= deferredApplied;
int i1 = 0;
while (i1 < budget && i1 < _deferredApply.Count) { ApplyResult(_deferredApply[i1]); i1++; }
if (i1 > 0) _deferredApply.RemoveRange(0, i1);
budget -= i1;
if (budget <= 0) return;
@ -385,13 +380,9 @@ public sealed class StreamingController
{
// Now apply up to remaining budget from deferred (mix from the
// chunk we just buffered + any pre-existing deferred items).
while (budget > 0 && _deferredApply.Count > 0)
{
var item = _deferredApply[0];
_deferredApply.RemoveAt(0);
ApplyResult(item);
budget--;
}
int i2 = 0;
while (i2 < budget && i2 < _deferredApply.Count) { ApplyResult(_deferredApply[i2]); i2++; }
if (i2 > 0) _deferredApply.RemoveRange(0, i2);
return;
}
// Priority not found in the outbox this frame: fall through to