From 3b1157780fc942e57ae16a34b3e818b3696622e7 Mon Sep 17 00:00:00 2001 From: Marcel Roozerkans Date: Fri, 22 May 2026 15:42:36 +0200 Subject: [PATCH] chore(deps): migrate to ZeroAlloc.TestHelpers for AllocationGate Removes the local samples/.../Internal/AllocationGate.cs and pulls the helper in via the new ZeroAlloc.TestHelpers package (ZeroAlloc-Net/ZeroAlloc.TestHelpers, source-only NuGet at contentFiles/cs/any/ZeroAlloc.TestHelpers/AllocationGate.cs). This consumer's previous local copy was the older/smaller version of the helper - missing AssertBudgetValueTask(...) that Mediator and Authorization had added later. After this migration, the smoke gets the full helper automatically. The smoke does not currently call the ValueTask overload; the capability is just available now. Closes the AllocationGate-copy-drift that motivated the factor-out (ZA.Mediator backlog #10). --- .../Internal/AllocationGate.cs | 31 ------------------- samples/ZeroAlloc.Mapping.AotSmoke/Program.cs | 2 +- .../ZeroAlloc.Mapping.AotSmoke.csproj | 7 +++++ .../AllocationBudgetTests.cs | 2 +- .../ZeroAlloc.Mapping.Tests.csproj | 8 ++--- 5 files changed, 13 insertions(+), 37 deletions(-) delete mode 100644 samples/ZeroAlloc.Mapping.AotSmoke/Internal/AllocationGate.cs diff --git a/samples/ZeroAlloc.Mapping.AotSmoke/Internal/AllocationGate.cs b/samples/ZeroAlloc.Mapping.AotSmoke/Internal/AllocationGate.cs deleted file mode 100644 index 4457cb6..0000000 --- a/samples/ZeroAlloc.Mapping.AotSmoke/Internal/AllocationGate.cs +++ /dev/null @@ -1,31 +0,0 @@ -namespace ZeroAlloc.Mapping.AotSmoke.Internal; - -internal static class AllocationGate -{ - public static void AssertBudget(int budgetBytes, int iterations, Action action, string label) - { - ArgumentNullException.ThrowIfNull(action); - if (iterations < 1) throw new ArgumentOutOfRangeException(nameof(iterations)); - - action(); - action(); - - GC.Collect(); - GC.WaitForPendingFinalizers(); - GC.Collect(); - - var before = GC.GetAllocatedBytesForCurrentThread(); - for (int i = 0; i < iterations; i++) action(); - var allocated = GC.GetAllocatedBytesForCurrentThread() - before; - - var perCall = allocated / iterations; - var totalBudget = (long)budgetBytes * iterations; - if (allocated > totalBudget) - { - throw new InvalidOperationException( - $"AllocationGate: {label} allocated {allocated} B total over {iterations} iterations " + - $"(~{perCall} B/call avg), budget is {budgetBytes} B/call ({totalBudget} B total). " + - "Use BenchmarkDotNet [MemoryDiagnoser] locally to find the culprit."); - } - } -} diff --git a/samples/ZeroAlloc.Mapping.AotSmoke/Program.cs b/samples/ZeroAlloc.Mapping.AotSmoke/Program.cs index 5862d70..9363c66 100644 --- a/samples/ZeroAlloc.Mapping.AotSmoke/Program.cs +++ b/samples/ZeroAlloc.Mapping.AotSmoke/Program.cs @@ -1,5 +1,5 @@ using ZeroAlloc.Mapping; -using ZeroAlloc.Mapping.AotSmoke.Internal; +using ZeroAlloc.TestHelpers; using ZeroAlloc.Results; namespace ZeroAlloc.Mapping.AotSmoke; diff --git a/samples/ZeroAlloc.Mapping.AotSmoke/ZeroAlloc.Mapping.AotSmoke.csproj b/samples/ZeroAlloc.Mapping.AotSmoke/ZeroAlloc.Mapping.AotSmoke.csproj index efb455e..98b5b21 100644 --- a/samples/ZeroAlloc.Mapping.AotSmoke/ZeroAlloc.Mapping.AotSmoke.csproj +++ b/samples/ZeroAlloc.Mapping.AotSmoke/ZeroAlloc.Mapping.AotSmoke.csproj @@ -25,4 +25,11 @@ ReferenceOutputAssembly="false" UndefineProperties="PublishAot" /> + + + + all + contentfiles;build + + diff --git a/tests/ZeroAlloc.Mapping.Tests/AllocationBudgetTests.cs b/tests/ZeroAlloc.Mapping.Tests/AllocationBudgetTests.cs index d0bad6f..205632c 100644 --- a/tests/ZeroAlloc.Mapping.Tests/AllocationBudgetTests.cs +++ b/tests/ZeroAlloc.Mapping.Tests/AllocationBudgetTests.cs @@ -1,4 +1,4 @@ -using ZeroAlloc.Mapping.AotSmoke.Internal; +using ZeroAlloc.TestHelpers; namespace ZeroAlloc.Mapping.Tests; diff --git a/tests/ZeroAlloc.Mapping.Tests/ZeroAlloc.Mapping.Tests.csproj b/tests/ZeroAlloc.Mapping.Tests/ZeroAlloc.Mapping.Tests.csproj index 20a020d..fcf322c 100644 --- a/tests/ZeroAlloc.Mapping.Tests/ZeroAlloc.Mapping.Tests.csproj +++ b/tests/ZeroAlloc.Mapping.Tests/ZeroAlloc.Mapping.Tests.csproj @@ -9,6 +9,10 @@ + + all + contentfiles;build + @@ -19,8 +23,4 @@ OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> - - -