diff --git a/Assets/Modules/ShrinkEventBus b/Assets/Modules/ShrinkEventBus index 901ad18..b14d6d0 160000 --- a/Assets/Modules/ShrinkEventBus +++ b/Assets/Modules/ShrinkEventBus @@ -1 +1 @@ -Subproject commit 901ad18453dd20e27240cf003846645199e699fd +Subproject commit b14d6d0117c9a558df356f12b9c9d57ffbeefbd1 diff --git a/Tools/AgentSupport/RuntimeTests/EventBusAllocationTests.cs b/Tools/AgentSupport/RuntimeTests/EventBusAllocationTests.cs new file mode 100644 index 0000000..13f590e --- /dev/null +++ b/Tools/AgentSupport/RuntimeTests/EventBusAllocationTests.cs @@ -0,0 +1,30 @@ +using System; +using NUnit.Framework; +using ShrinkEventBus; + +[TestFixture, NonParallelizable] +public class EventBusAllocationTests +{ + private readonly struct ProbeEvent : IShrinkEvent { } + + [Test] + public void PublicDiagnosticsDoesNotAllocatePerPostAfterWarmup() + { + using var host = new ShrinkEventBusHost(); + var bus = host.CreateBus(new ShrinkBusKey("allocation", "probe"), ShrinkBusOptions.Inline()); + var calls = 0; + using var observer = EventBus.ObserveDiagnostics(_ => calls++); + Measure(bus); + var allocated = Measure(bus); + Assert.That(calls, Is.EqualTo(20000)); + Assert.That(allocated, Is.Zero); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + private static long Measure(IShrinkEventBus bus) + { + var before = GC.GetAllocatedBytesForCurrentThread(); + for (var i = 0; i < 10000; i++) bus.Post(new ProbeEvent()); + return GC.GetAllocatedBytesForCurrentThread() - before; + } +} diff --git a/Tools/Release/package-versions.json b/Tools/Release/package-versions.json index e6cdb08..6425316 100644 --- a/Tools/Release/package-versions.json +++ b/Tools/Release/package-versions.json @@ -160,12 +160,12 @@ { "directory": "ShrinkEventBus", "name": "com.cneicy.shrink-eventbus", - "version": "2.3.1", + "version": "2.3.2", "repository": "https://git.crash.work/ShrinkSDK/ShrinkEventBus.git", "nugetPackages": [ { "id": "ShrinkSDK.EventBus", - "version": "2.3.1", + "version": "2.3.2", "project": "Assets/Modules/ShrinkEventBus/DotNet~/ShrinkSDK.EventBus.csproj" } ]