perf(runtime): remove measured steady allocations

Eliminate boxed production surface-override enumeration, retain vital modifier projections until the enchantment registry mutates, and measure DAT font widths without allocating a captured delegate. Preserve exact hashes, spell stacking, and glyph advances with warmed zero-allocation tests.

Validated by the focused rendering, UI, and spell suites, a zero-error Release build, and 8,409 passing Release tests with five pre-existing skips.

Co-authored-by: Codex <codex@openai.com>
This commit is contained in:
Erik 2026-07-25 17:50:30 +02:00
parent 574a6c454f
commit feb80a67d9
6 changed files with 188 additions and 14 deletions

View file

@ -90,6 +90,59 @@ public sealed class SpellbookTests
Assert.Equal(2, book.ActiveCount);
}
[Fact]
public void GetVitalMod_ReusesCachedValueUntilEnchantmentsChange()
{
SpellTable table = SpellTable.Create(
[
TestSpell(42u) with { Family = 100u },
]);
var book = new Spellbook(table);
book.OnEnchantmentAdded(new ActiveEnchantmentRecord(
SpellId: 42u,
LayerId: 7u,
Duration: 300f,
CasterGuid: 0u,
StatModKey: EnchantmentMath.StatKey.MaxHealth,
StatModValue: 1.5f,
Bucket: 1u));
Assert.Equal(
1.5f,
book.GetVitalMod(EnchantmentMath.StatKey.MaxHealth).Multiplier);
EnchantmentMath.VitalMod actual = default;
// Cross the tiered-PGO call threshold before measuring the retained
// lookup itself. Otherwise a full parallel solution run can attribute
// runtime tier-promotion bookkeeping to this thread.
for (int iteration = 0; iteration < 10_000; iteration++)
actual = book.GetVitalMod(EnchantmentMath.StatKey.MaxHealth);
long before = GC.GetAllocatedBytesForCurrentThread();
for (int iteration = 0; iteration < 10_000; iteration++)
{
actual =
book.GetVitalMod(EnchantmentMath.StatKey.MaxHealth);
}
long allocated = GC.GetAllocatedBytesForCurrentThread() - before;
Assert.Equal(1.5f, actual.Multiplier);
Assert.Equal(0, allocated);
book.OnEnchantmentAdded(new ActiveEnchantmentRecord(
SpellId: 42u,
LayerId: 7u,
Duration: 300f,
CasterGuid: 0u,
StatModKey: EnchantmentMath.StatKey.MaxHealth,
StatModValue: 1.25f,
Bucket: 1u));
Assert.Equal(
1.25f,
book.GetVitalMod(EnchantmentMath.StatKey.MaxHealth).Multiplier);
}
[Fact]
public void LiveEnchantments_NewIdentityInsertsAtRetailListHead()
{