perf: reduce diagnostics and queued dispatch allocations in 2.3.2
Publish UPM package / publish (push) Successful in 2s
Publish NuGet packages / publish (push) Canceled after 3m12s

This commit is contained in:
cneicy committed 2026-11-06 20:52:09 +08:00
1 parent 901ad18453
commit 0449e82c0c
8 files changed
+152 -36

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
using ShrinkEventBus;
using var host = new ShrinkEventBusHost();
var bus = host.CreateBus(ShrinkBusKey.Game, ShrinkBusOptions.Inline());
var subscriber = new OrderSubscriber();
using var binding = host.Attach(subscriber);
var diagnostics = 0;
using var observation = EventBus.ObserveDiagnostics(_ => diagnostics++);
bus.Post(new OrderPlaced(2));
await bus.PostAsync(new OrderPlaced(3));
if (subscriber.Total != 5 || diagnostics != 2)
throw new InvalidOperationException("Generated subscription or diagnostics failed.");
var workerKey = new ShrinkBusKey("worker", "orders");
var worker = host.CreateBus(workerKey, ShrinkBusOptions.DedicatedThread());
var workerSubscriber = new OrderSubscriber();
using var workerBinding = host.Attach(workerSubscriber, workerKey);
await worker.PostAsync(new OrderPlaced(7));
if (workerSubscriber.Total != 7)
throw new InvalidOperationException("Dedicated-thread delivery failed.");
binding.Dispose();
bus.Post(new OrderPlaced(10));
if (subscriber.Total != 5)
throw new InvalidOperationException("Unsubscribe failed.");
await host.ShutdownAsync();
Console.WriteLine("EVENTBUS_CONSOLE_PASS: sync, async, diagnostics, worker, unsubscribe");
public readonly record struct OrderPlaced(int Amount) : IShrinkEvent;
[ShrinkEventSubscriber]
public sealed partial class OrderSubscriber
{
public int Total { get; private set; }
[ShrinkSubscribe]
private void OnOrder(OrderPlaced order) => Total += order.Amount;
}