com.wallstop-studios.dxmessaging 2.0.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/format-on-demand.yml +2 -2
- package/.github/workflows/json-format-check.yml +1 -1
- package/.github/workflows/markdown-json.yml +1 -1
- package/.github/workflows/markdownlint.yml +1 -1
- package/.github/workflows/npm-publish.yml +1 -1
- package/.github/workflows/prettier-autofix.yml +2 -2
- package/.github/workflows/yaml-format-lint.yml +1 -1
- package/Docs/Advanced.md +26 -1
- package/Docs/Comparisons.md +1229 -146
- package/Docs/Compatibility.md +27 -0
- package/Docs/DesignAndArchitecture.md +41 -34
- package/Docs/EmitShorthands.md +34 -0
- package/Docs/Helpers.md +91 -76
- package/Docs/Index.md +28 -25
- package/Docs/Install.md +29 -6
- package/Docs/Integrations/Reflex.md +292 -0
- package/{package-lock.json.meta → Docs/Integrations/Reflex.md.meta} +1 -1
- package/Docs/Integrations/VContainer.md +324 -0
- package/Docs/Integrations/VContainer.md.meta +7 -0
- package/Docs/Integrations/Zenject.md +333 -0
- package/Docs/Integrations/Zenject.md.meta +7 -0
- package/{Editor/Analyzers/WallstopStudios.DxMessaging.SourceGenerators.pdb.meta → Docs/Integrations.meta} +2 -1
- package/Docs/InterceptorsAndOrdering.md +371 -17
- package/Docs/ListeningPatterns.md +206 -0
- package/Docs/MessageBusProviders.md +496 -0
- package/Docs/MessageBusProviders.md.meta +7 -0
- package/Docs/MessageTypes.md +27 -0
- package/Docs/MigrationGuide.md +45 -0
- package/Docs/Patterns.md +286 -0
- package/Docs/Performance.md +9 -9
- package/Docs/QuickReference.md +31 -0
- package/Docs/QuickStart.md +1 -2
- package/Docs/RuntimeConfiguration.md +407 -0
- package/Docs/RuntimeConfiguration.md.meta +7 -0
- package/Docs/UnityIntegration.md +3 -1
- package/Docs/VisualGuide.md +206 -157
- package/Editor/CustomEditors/MessagingComponentEditor.cs +15 -6
- package/README.md +148 -26
- package/Runtime/AssemblyInfo.cs +4 -0
- package/Runtime/Core/Attributes/DxAutoConstructorAttribute.cs +1 -1
- package/Runtime/Core/Attributes/DxBroadcastMessageAttribute.cs +1 -1
- package/Runtime/Core/Attributes/DxOptionalParameterAttribute.cs +1 -1
- package/Runtime/Core/Attributes/DxTargetedMessageAttribute.cs +1 -1
- package/Runtime/Core/Attributes/DxUntargetedMessageAttribute.cs +1 -1
- package/Runtime/Core/Extensions/MessageBusExtensions.cs +253 -0
- package/Runtime/Core/Extensions/MessageBusExtensions.cs.meta +12 -0
- package/Runtime/Core/Extensions/MessageExtensions.cs +137 -89
- package/Runtime/Core/MessageBus/GlobalMessageBusProvider.cs +23 -0
- package/Runtime/Core/MessageBus/GlobalMessageBusProvider.cs.meta +11 -0
- package/Runtime/Core/MessageBus/IMessageBusProvider.cs +14 -0
- package/Runtime/Core/MessageBus/IMessageBusProvider.cs.meta +11 -0
- package/Runtime/Core/MessageBus/IMessageRegistrationBuilder.cs +18 -0
- package/Runtime/Core/MessageBus/IMessageRegistrationBuilder.cs.meta +11 -0
- package/Runtime/Core/MessageBus/MessageBusRebindMode.cs +26 -0
- package/Runtime/Core/MessageBus/MessageBusRebindMode.cs.meta +11 -0
- package/Runtime/Core/MessageBus/MessageRegistrationBuilder.cs +383 -0
- package/Runtime/Core/MessageBus/MessageRegistrationBuilder.cs.meta +11 -0
- package/Runtime/Core/MessageHandler.cs +198 -27
- package/Runtime/Core/MessageRegistrationToken.cs +67 -25
- package/Runtime/Core/Messages/IBroadcastMessage.cs +1 -1
- package/Runtime/Core/Messages/ITargetedMessage.cs +1 -1
- package/Runtime/Core/Messages/IUntargetedMessage.cs +1 -1
- package/Runtime/Unity/CurrentGlobalMessageBusProvider.cs +31 -0
- package/Runtime/Unity/CurrentGlobalMessageBusProvider.cs.meta +12 -0
- package/Runtime/Unity/InitialGlobalMessageBusProvider.cs +38 -0
- package/Runtime/Unity/InitialGlobalMessageBusProvider.cs.meta +12 -0
- package/Runtime/Unity/Integrations/Reflex/AssemblyInfo.cs +11 -0
- package/Runtime/Unity/Integrations/Reflex/AssemblyInfo.cs.meta +3 -0
- package/Runtime/Unity/Integrations/Reflex/ReflexRegistrationInstaller.cs +73 -0
- package/Runtime/Unity/Integrations/Reflex/ReflexRegistrationInstaller.cs.meta +11 -0
- package/Runtime/Unity/Integrations/Reflex/WallstopStudios.DxMessaging.Reflex.asmdef +20 -0
- package/Runtime/Unity/Integrations/Reflex/WallstopStudios.DxMessaging.Reflex.asmdef.meta +7 -0
- package/Runtime/Unity/Integrations/Reflex.meta +8 -0
- package/Runtime/Unity/Integrations/VContainer/AssemblyInfo.cs +11 -0
- package/Runtime/Unity/Integrations/VContainer/AssemblyInfo.cs.meta +3 -0
- package/Runtime/Unity/Integrations/VContainer/VContainerRegistrationExtensions.cs +46 -0
- package/Runtime/Unity/Integrations/VContainer/VContainerRegistrationExtensions.cs.meta +11 -0
- package/Runtime/Unity/Integrations/VContainer/WallstopStudios.DxMessaging.VContainer.asmdef +30 -0
- package/Runtime/Unity/Integrations/VContainer/WallstopStudios.DxMessaging.VContainer.asmdef.meta +7 -0
- package/Runtime/Unity/Integrations/VContainer.meta +8 -0
- package/Runtime/Unity/Integrations/Zenject/AssemblyInfo.cs +11 -0
- package/Runtime/Unity/Integrations/Zenject/AssemblyInfo.cs.meta +3 -0
- package/Runtime/Unity/Integrations/Zenject/WallstopStudios.DxMessaging.Zenject.asmdef +30 -0
- package/Runtime/Unity/Integrations/Zenject/WallstopStudios.DxMessaging.Zenject.asmdef.meta +7 -0
- package/Runtime/Unity/Integrations/Zenject/ZenjectRegistrationInstaller.cs +55 -0
- package/Runtime/Unity/Integrations/Zenject/ZenjectRegistrationInstaller.cs.meta +11 -0
- package/Runtime/Unity/Integrations/Zenject.meta +8 -0
- package/Runtime/Unity/Integrations.meta +8 -0
- package/Runtime/Unity/MessageAwareComponent.cs +102 -0
- package/Runtime/Unity/MessageBusProviderHandle.cs +97 -0
- package/Runtime/Unity/MessageBusProviderHandle.cs.meta +12 -0
- package/Runtime/Unity/MessagingComponent.cs +175 -9
- package/Runtime/Unity/MessagingComponentInstaller.cs +120 -0
- package/Runtime/Unity/MessagingComponentInstaller.cs.meta +12 -0
- package/Runtime/Unity/ScriptableMessageBusProvider.cs +14 -0
- package/Runtime/Unity/ScriptableMessageBusProvider.cs.meta +12 -0
- package/Samples~/DI/Prefabs/MessagingInstallerSample.prefab +98 -0
- package/Samples~/DI/Prefabs/MessagingInstallerSample.prefab.meta +7 -0
- package/Samples~/DI/Prefabs.meta +8 -0
- package/Samples~/DI/Providers/GlobalMessageBusProvider.asset +14 -0
- package/Samples~/DI/Providers/GlobalMessageBusProvider.asset.meta +8 -0
- package/Samples~/DI/Providers/InitialGlobalMessageBusProvider.asset +14 -0
- package/Samples~/DI/Providers/InitialGlobalMessageBusProvider.asset.meta +8 -0
- package/Samples~/DI/Providers.meta +8 -0
- package/Samples~/DI/README.md +51 -0
- package/Samples~/DI/README.md.meta +7 -0
- package/Samples~/DI/Reflex/SampleInstaller.cs +75 -0
- package/Samples~/DI/Reflex/SampleInstaller.cs.meta +11 -0
- package/Samples~/DI/Reflex.meta +8 -0
- package/Samples~/DI/VContainer/SampleLifetimeScope.cs +79 -0
- package/Samples~/DI/VContainer/SampleLifetimeScope.cs.meta +11 -0
- package/Samples~/DI/VContainer.meta +8 -0
- package/Samples~/DI/Zenject/SampleInstaller.cs +65 -0
- package/Samples~/DI/Zenject/SampleInstaller.cs.meta +11 -0
- package/Samples~/DI/Zenject.meta +8 -0
- package/Samples~/DI.meta +8 -0
- package/Samples~/Mini Combat/README.md +5 -7
- package/Samples~/Mini Combat/Walkthrough.md +18 -24
- package/Samples~/UI Buttons + Inspector/DiagnosticsEnabler.cs +12 -2
- package/Samples~/UI Buttons + Inspector/README.md.meta +7 -0
- package/Tests/Runtime/Benchmarks/BenchmarkSession.cs +444 -0
- package/Tests/Runtime/Benchmarks/BenchmarkSession.cs.meta +11 -0
- package/Tests/Runtime/Benchmarks/BenchmarkTestBase.cs +94 -0
- package/Tests/Runtime/Benchmarks/BenchmarkTestBase.cs.meta +11 -0
- package/Tests/Runtime/Benchmarks/ComparisonPerformanceTests.cs +395 -0
- package/Tests/Runtime/Benchmarks/ComparisonPerformanceTests.cs.meta +11 -0
- package/Tests/Runtime/Benchmarks/PerformanceTests.cs +77 -429
- package/Tests/Runtime/Benchmarks/ProviderResolutionBenchmarks.cs +142 -0
- package/Tests/Runtime/Benchmarks/ProviderResolutionBenchmarks.cs.meta +12 -0
- package/Tests/Runtime/Benchmarks/WallstopStudios.DxMessaging.Tests.Runtime.Benchmarks.asmdef +50 -0
- package/Tests/Runtime/Benchmarks/WallstopStudios.DxMessaging.Tests.Runtime.Benchmarks.asmdef.meta +7 -0
- package/Tests/Runtime/Core/DefaultBusFallbackTests.cs +333 -0
- package/Tests/Runtime/Core/DefaultBusFallbackTests.cs.meta +11 -0
- package/Tests/Runtime/Core/Extensions/MessageBusExtensionsTests.cs +278 -0
- package/Tests/Runtime/Core/Extensions/MessageBusExtensionsTests.cs.meta +11 -0
- package/Tests/Runtime/Core/Extensions/MessageExtensionsProviderTests.cs +289 -0
- package/Tests/Runtime/Core/Extensions/MessageExtensionsProviderTests.cs.meta +11 -0
- package/Tests/Runtime/Core/Extensions.meta +8 -0
- package/Tests/Runtime/Core/IntegrationShimSmokeTests.cs +57 -0
- package/Tests/Runtime/Core/IntegrationShimSmokeTests.cs.meta +11 -0
- package/Tests/Runtime/Core/MessageHandlerGlobalBusTests.cs +219 -0
- package/Tests/Runtime/Core/MessageHandlerGlobalBusTests.cs.meta +11 -0
- package/Tests/Runtime/Core/MessageRegistrationBuilderTests.cs +204 -0
- package/Tests/Runtime/Core/MessageRegistrationBuilderTests.cs.meta +11 -0
- package/Tests/Runtime/Core/MessagingTestBase.cs +4 -4
- package/Tests/Runtime/Core/NominalTests.cs +2 -2
- package/Tests/Runtime/Core/TypedShorthandTests.cs +2 -2
- package/Tests/Runtime/Core/UntargetedEquivalenceTests.cs +1 -1
- package/Tests/Runtime/Core/UntargetedPrefreezeTests.cs +2 -4
- package/Tests/Runtime/Integrations/Reflex/ReflexIntegrationTests.cs +162 -0
- package/Tests/Runtime/Integrations/Reflex/ReflexIntegrationTests.cs.meta +11 -0
- package/Tests/Runtime/Integrations/Reflex/Resources/ReflexSettings.asset +16 -0
- package/Tests/Runtime/Integrations/Reflex/Resources/ReflexSettings.asset.meta +8 -0
- package/Tests/Runtime/Integrations/Reflex/Resources.meta +8 -0
- package/Tests/Runtime/Integrations/Reflex/WallstopStudios.DxMessaging.Tests.Runtime.Reflex.asmdef +27 -0
- package/Tests/Runtime/Integrations/Reflex/WallstopStudios.DxMessaging.Tests.Runtime.Reflex.asmdef.meta +7 -0
- package/Tests/Runtime/Integrations/Reflex.meta +8 -0
- package/Tests/Runtime/Integrations/VContainer/VContainerIntegrationTests.cs +140 -0
- package/Tests/Runtime/Integrations/VContainer/VContainerIntegrationTests.cs.meta +11 -0
- package/Tests/Runtime/Integrations/VContainer/WallstopStudios.DxMessaging.Tests.Runtime.VContainer.asmdef +37 -0
- package/Tests/Runtime/Integrations/VContainer/WallstopStudios.DxMessaging.Tests.Runtime.VContainer.asmdef.meta +7 -0
- package/Tests/Runtime/Integrations/VContainer.meta +8 -0
- package/Tests/Runtime/Integrations/Zenject/WallstopStudios.DxMessaging.Tests.Runtime.Zenject.asmdef +37 -0
- package/Tests/Runtime/Integrations/Zenject/WallstopStudios.DxMessaging.Tests.Runtime.Zenject.asmdef.meta +7 -0
- package/Tests/Runtime/Integrations/Zenject/ZenjectIntegrationTests.cs +140 -0
- package/Tests/Runtime/Integrations/Zenject/ZenjectIntegrationTests.cs.meta +11 -0
- package/Tests/Runtime/Integrations/Zenject.meta +8 -0
- package/Tests/Runtime/Integrations.meta +8 -0
- package/Tests/Runtime/Scripts/Components/EmptyMessageAwareComponent.cs +1 -1
- package/Tests/Runtime/Scripts/Components/GenericMessageAwareComponent.cs +1 -1
- package/Tests/Runtime/Scripts/Components/SimpleMessageAwareComponent.cs +1 -1
- package/Tests/Runtime/TestUtilities/UnityFixtureBase.cs +64 -0
- package/Tests/Runtime/TestUtilities/UnityFixtureBase.cs.meta +12 -0
- package/Tests/Runtime/TestUtilities.meta +9 -0
- package/Tests/Runtime/Unity/MessageBusProviderAssetTests.cs +57 -0
- package/Tests/Runtime/Unity/MessageBusProviderAssetTests.cs.meta +11 -0
- package/Tests/Runtime/Unity/MessageBusProviderHandleTests.cs +107 -0
- package/Tests/Runtime/Unity/MessageBusProviderHandleTests.cs.meta +12 -0
- package/Tests/Runtime/Unity/MessagingComponentProviderIntegrationTests.cs +210 -0
- package/Tests/Runtime/Unity/MessagingComponentProviderIntegrationTests.cs.meta +12 -0
- package/Tests/Runtime/Unity.meta +9 -0
- package/Tests/Runtime/WallstopStudios.DxMessaging.Tests.Runtime.asmdef +3 -1
- package/package.json +1 -1
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
namespace DxMessaging.Tests.Runtime.Benchmarks
|
|
2
|
+
{
|
|
3
|
+
using System;
|
|
4
|
+
using System.Diagnostics;
|
|
5
|
+
using DxMessaging.Core;
|
|
6
|
+
using DxMessaging.Core.Extensions;
|
|
7
|
+
using NUnit.Framework;
|
|
8
|
+
using Scripts.Messages;
|
|
9
|
+
using UnityEngine.TestTools.Constraints;
|
|
10
|
+
using Debug = UnityEngine.Debug;
|
|
11
|
+
using Is = NUnit.Framework.Is;
|
|
12
|
+
#if UNIRX_PRESENT
|
|
13
|
+
using UniRx;
|
|
14
|
+
#endif
|
|
15
|
+
#if MESSAGEPIPE_PRESENT
|
|
16
|
+
using MessagePipe;
|
|
17
|
+
#endif
|
|
18
|
+
#if ZENJECT_PRESENT
|
|
19
|
+
using Zenject;
|
|
20
|
+
#endif
|
|
21
|
+
|
|
22
|
+
public sealed class ComparisonPerformanceTests : BenchmarkTestBase
|
|
23
|
+
{
|
|
24
|
+
protected override bool MessagingDebugEnabled => false;
|
|
25
|
+
|
|
26
|
+
[Test]
|
|
27
|
+
public void Benchmark()
|
|
28
|
+
{
|
|
29
|
+
string operatingSystemSection = BenchmarkDocumentation.GetOperatingSystemSection();
|
|
30
|
+
string sectionName = string.IsNullOrEmpty(operatingSystemSection)
|
|
31
|
+
? null
|
|
32
|
+
: $"Comparisons ({operatingSystemSection})";
|
|
33
|
+
|
|
34
|
+
BenchmarkSession session = new(
|
|
35
|
+
sectionName,
|
|
36
|
+
"### ",
|
|
37
|
+
new Func<string>[]
|
|
38
|
+
{
|
|
39
|
+
BenchmarkDocumentation.TryFindComparisonsDocPath,
|
|
40
|
+
BenchmarkDocumentation.TryFindPerformanceDocPath,
|
|
41
|
+
BenchmarkDocumentation.TryFindReadmePath,
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
RunWithSession(
|
|
46
|
+
session,
|
|
47
|
+
() =>
|
|
48
|
+
{
|
|
49
|
+
TimeSpan timeout = TimeSpan.FromSeconds(5);
|
|
50
|
+
BenchmarkDxMessaging(timeout);
|
|
51
|
+
BenchmarkUniRx(timeout);
|
|
52
|
+
BenchmarkMessagePipe(timeout);
|
|
53
|
+
BenchmarkZenjectSignals(timeout);
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private void BenchmarkDxMessaging(TimeSpan timeout)
|
|
59
|
+
{
|
|
60
|
+
Stopwatch timer = Stopwatch.StartNew();
|
|
61
|
+
SimpleUntargetedMessage message = new();
|
|
62
|
+
|
|
63
|
+
RunWithComponent(component =>
|
|
64
|
+
{
|
|
65
|
+
int count = 0;
|
|
66
|
+
MessageRegistrationToken token = GetToken(component);
|
|
67
|
+
token.RegisterUntargeted<SimpleUntargetedMessage>(Handle);
|
|
68
|
+
|
|
69
|
+
message.EmitUntargeted();
|
|
70
|
+
|
|
71
|
+
timer.Restart();
|
|
72
|
+
do
|
|
73
|
+
{
|
|
74
|
+
for (int i = 0; i < NumInvocationsPerIteration; ++i)
|
|
75
|
+
{
|
|
76
|
+
message.EmitUntargeted();
|
|
77
|
+
}
|
|
78
|
+
} while (timer.Elapsed < timeout);
|
|
79
|
+
|
|
80
|
+
bool allocating;
|
|
81
|
+
try
|
|
82
|
+
{
|
|
83
|
+
Assert.That(() => message.EmitUntargeted(), Is.Not.AllocatingGCMemory());
|
|
84
|
+
allocating = false;
|
|
85
|
+
}
|
|
86
|
+
catch
|
|
87
|
+
{
|
|
88
|
+
allocating = true;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
RecordBenchmark("DxMessaging (Untargeted) - No-Copy", count, timeout, allocating);
|
|
92
|
+
return;
|
|
93
|
+
|
|
94
|
+
void Handle(ref SimpleUntargetedMessage _)
|
|
95
|
+
{
|
|
96
|
+
++count;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
#if ZENJECT_PRESENT
|
|
102
|
+
private void BenchmarkZenjectSignals(TimeSpan timeout)
|
|
103
|
+
{
|
|
104
|
+
ZenjectBridge bridge = ZenjectBridge.Create();
|
|
105
|
+
if (bridge == null)
|
|
106
|
+
{
|
|
107
|
+
Debug.LogWarning("Zenject SignalBus not found. Skipping comparison benchmark.");
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
SimpleUntargetedMessage message = new();
|
|
112
|
+
int count = 0;
|
|
113
|
+
using IDisposable subscription = bridge.Subscribe(_ => ++count);
|
|
114
|
+
|
|
115
|
+
bridge.Publish(message);
|
|
116
|
+
|
|
117
|
+
Stopwatch timer = Stopwatch.StartNew();
|
|
118
|
+
do
|
|
119
|
+
{
|
|
120
|
+
for (int i = 0; i < NumInvocationsPerIteration; ++i)
|
|
121
|
+
{
|
|
122
|
+
bridge.Publish(message);
|
|
123
|
+
}
|
|
124
|
+
} while (timer.Elapsed < timeout);
|
|
125
|
+
|
|
126
|
+
bool allocating;
|
|
127
|
+
try
|
|
128
|
+
{
|
|
129
|
+
Assert.That(() => bridge.Publish(message), Is.Not.AllocatingGCMemory());
|
|
130
|
+
allocating = false;
|
|
131
|
+
}
|
|
132
|
+
catch
|
|
133
|
+
{
|
|
134
|
+
allocating = true;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
RecordBenchmark("Zenject SignalBus", count, timeout, allocating);
|
|
138
|
+
}
|
|
139
|
+
#else
|
|
140
|
+
private void BenchmarkZenjectSignals(TimeSpan timeout)
|
|
141
|
+
{
|
|
142
|
+
Debug.LogWarning("Zenject package not detected. Skipping comparison benchmark.");
|
|
143
|
+
}
|
|
144
|
+
#endif
|
|
145
|
+
|
|
146
|
+
#if UNIRX_PRESENT
|
|
147
|
+
private void BenchmarkUniRx(TimeSpan timeout)
|
|
148
|
+
{
|
|
149
|
+
UniRxBridge bridge = UniRxBridge.Create();
|
|
150
|
+
if (bridge == null)
|
|
151
|
+
{
|
|
152
|
+
Debug.LogWarning("UniRx.MessageBroker not found. Skipping comparison benchmark.");
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
SimpleUntargetedMessage message = new();
|
|
157
|
+
int count = 0;
|
|
158
|
+
using IDisposable subscription = bridge.Subscribe(_ => ++count);
|
|
159
|
+
|
|
160
|
+
bridge.Publish(message);
|
|
161
|
+
|
|
162
|
+
Stopwatch timer = Stopwatch.StartNew();
|
|
163
|
+
do
|
|
164
|
+
{
|
|
165
|
+
for (int i = 0; i < NumInvocationsPerIteration; ++i)
|
|
166
|
+
{
|
|
167
|
+
bridge.Publish(message);
|
|
168
|
+
}
|
|
169
|
+
} while (timer.Elapsed < timeout);
|
|
170
|
+
|
|
171
|
+
bool allocating;
|
|
172
|
+
try
|
|
173
|
+
{
|
|
174
|
+
Assert.That(() => bridge.Publish(message), Is.Not.AllocatingGCMemory());
|
|
175
|
+
allocating = false;
|
|
176
|
+
}
|
|
177
|
+
catch
|
|
178
|
+
{
|
|
179
|
+
allocating = true;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
RecordBenchmark("UniRx MessageBroker", count, timeout, allocating);
|
|
183
|
+
}
|
|
184
|
+
#else
|
|
185
|
+
private void BenchmarkUniRx(TimeSpan timeout)
|
|
186
|
+
{
|
|
187
|
+
Debug.LogWarning("UniRx package not detected. Skipping comparison benchmark.");
|
|
188
|
+
}
|
|
189
|
+
#endif
|
|
190
|
+
|
|
191
|
+
#if MESSAGEPIPE_PRESENT
|
|
192
|
+
private void BenchmarkMessagePipe(TimeSpan timeout)
|
|
193
|
+
{
|
|
194
|
+
MessagePipeBridge bridge = MessagePipeBridge.Create();
|
|
195
|
+
if (bridge == null)
|
|
196
|
+
{
|
|
197
|
+
Debug.LogWarning("Cysharp.MessagePipe not found. Skipping comparison benchmark.");
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
SimpleUntargetedMessage message = new();
|
|
202
|
+
int count = 0;
|
|
203
|
+
using IDisposable subscription = bridge.Subscribe(_ => ++count);
|
|
204
|
+
|
|
205
|
+
bridge.Publish(message);
|
|
206
|
+
|
|
207
|
+
Stopwatch timer = Stopwatch.StartNew();
|
|
208
|
+
do
|
|
209
|
+
{
|
|
210
|
+
for (int i = 0; i < NumInvocationsPerIteration; ++i)
|
|
211
|
+
{
|
|
212
|
+
bridge.Publish(message);
|
|
213
|
+
}
|
|
214
|
+
} while (timer.Elapsed < timeout);
|
|
215
|
+
|
|
216
|
+
bool allocating;
|
|
217
|
+
try
|
|
218
|
+
{
|
|
219
|
+
Assert.That(() => bridge.Publish(message), Is.Not.AllocatingGCMemory());
|
|
220
|
+
allocating = false;
|
|
221
|
+
}
|
|
222
|
+
catch
|
|
223
|
+
{
|
|
224
|
+
allocating = true;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
RecordBenchmark("MessagePipe (Global)", count, timeout, allocating);
|
|
228
|
+
}
|
|
229
|
+
#else
|
|
230
|
+
private void BenchmarkMessagePipe(TimeSpan timeout)
|
|
231
|
+
{
|
|
232
|
+
Debug.LogWarning("MessagePipe package not detected. Skipping comparison benchmark.");
|
|
233
|
+
}
|
|
234
|
+
#endif
|
|
235
|
+
|
|
236
|
+
#if UNIRX_PRESENT
|
|
237
|
+
private sealed class UniRxBridge
|
|
238
|
+
{
|
|
239
|
+
private readonly IMessageBroker _broker;
|
|
240
|
+
|
|
241
|
+
private UniRxBridge(IMessageBroker broker)
|
|
242
|
+
{
|
|
243
|
+
_broker = broker;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
internal static UniRxBridge Create()
|
|
247
|
+
{
|
|
248
|
+
IMessageBroker broker = MessageBroker.Default;
|
|
249
|
+
if (broker == null)
|
|
250
|
+
{
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return new UniRxBridge(broker);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
internal IDisposable Subscribe(Action<SimpleUntargetedMessage> handler)
|
|
258
|
+
{
|
|
259
|
+
return _broker.Receive<SimpleUntargetedMessage>().Subscribe(handler);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
internal void Publish(in SimpleUntargetedMessage message)
|
|
263
|
+
{
|
|
264
|
+
_broker.Publish(message);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
#endif
|
|
268
|
+
|
|
269
|
+
#if MESSAGEPIPE_PRESENT
|
|
270
|
+
private sealed class MessagePipeBridge
|
|
271
|
+
{
|
|
272
|
+
private readonly IPublisher<SimpleUntargetedMessage> _publisher;
|
|
273
|
+
private readonly ISubscriber<SimpleUntargetedMessage> _subscriber;
|
|
274
|
+
|
|
275
|
+
private MessagePipeBridge(
|
|
276
|
+
IPublisher<SimpleUntargetedMessage> publisher,
|
|
277
|
+
ISubscriber<SimpleUntargetedMessage> subscriber
|
|
278
|
+
)
|
|
279
|
+
{
|
|
280
|
+
_publisher = publisher;
|
|
281
|
+
_subscriber = subscriber;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
internal static MessagePipeBridge Create()
|
|
285
|
+
{
|
|
286
|
+
try
|
|
287
|
+
{
|
|
288
|
+
BuiltinContainerBuilder builder = new();
|
|
289
|
+
builder.AddMessagePipe();
|
|
290
|
+
builder.AddMessageBroker<SimpleUntargetedMessage>();
|
|
291
|
+
IServiceProvider provider = builder.BuildServiceProvider();
|
|
292
|
+
GlobalMessagePipe.SetProvider(provider);
|
|
293
|
+
IPublisher<SimpleUntargetedMessage> publisher =
|
|
294
|
+
GlobalMessagePipe.GetPublisher<SimpleUntargetedMessage>();
|
|
295
|
+
ISubscriber<SimpleUntargetedMessage> subscriber =
|
|
296
|
+
GlobalMessagePipe.GetSubscriber<SimpleUntargetedMessage>();
|
|
297
|
+
if (publisher == null || subscriber == null)
|
|
298
|
+
{
|
|
299
|
+
if (provider is IDisposable disposable)
|
|
300
|
+
{
|
|
301
|
+
disposable.Dispose();
|
|
302
|
+
}
|
|
303
|
+
Debug.LogWarning(
|
|
304
|
+
"MessagePipe publisher or subscriber could not be resolved."
|
|
305
|
+
);
|
|
306
|
+
return null;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return new MessagePipeBridge(publisher, subscriber);
|
|
310
|
+
}
|
|
311
|
+
catch (Exception exception)
|
|
312
|
+
{
|
|
313
|
+
Debug.LogWarning($"MessagePipe setup failed: {exception}");
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
internal IDisposable Subscribe(Action<SimpleUntargetedMessage> handler)
|
|
319
|
+
{
|
|
320
|
+
return _subscriber.Subscribe(handler);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
internal void Publish(in SimpleUntargetedMessage message)
|
|
324
|
+
{
|
|
325
|
+
_publisher.Publish(message);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
#endif
|
|
329
|
+
|
|
330
|
+
#if ZENJECT_PRESENT
|
|
331
|
+
private sealed class ZenjectBridge
|
|
332
|
+
{
|
|
333
|
+
private readonly SignalBus _signalBus;
|
|
334
|
+
|
|
335
|
+
private ZenjectBridge(SignalBus signalBus)
|
|
336
|
+
{
|
|
337
|
+
_signalBus = signalBus;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
internal static ZenjectBridge Create()
|
|
341
|
+
{
|
|
342
|
+
try
|
|
343
|
+
{
|
|
344
|
+
DiContainer container = new();
|
|
345
|
+
SignalBusInstaller.Install(container);
|
|
346
|
+
container.DeclareSignal<SimpleUntargetedMessage>();
|
|
347
|
+
container.ResolveRoots();
|
|
348
|
+
SignalBus signalBus = container.Resolve<SignalBus>();
|
|
349
|
+
return new ZenjectBridge(signalBus);
|
|
350
|
+
}
|
|
351
|
+
catch (Exception exception)
|
|
352
|
+
{
|
|
353
|
+
Debug.LogWarning($"Zenject SignalBus setup failed: {exception}");
|
|
354
|
+
return null;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
internal IDisposable Subscribe(Action<SimpleUntargetedMessage> handler)
|
|
359
|
+
{
|
|
360
|
+
return new Subscription(_signalBus, handler);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
internal void Publish(in SimpleUntargetedMessage message)
|
|
364
|
+
{
|
|
365
|
+
_signalBus.Fire(message);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
private sealed class Subscription : IDisposable
|
|
369
|
+
{
|
|
370
|
+
private readonly SignalBus _signalBus;
|
|
371
|
+
private readonly Action<SimpleUntargetedMessage> _handler;
|
|
372
|
+
private bool _disposed;
|
|
373
|
+
|
|
374
|
+
internal Subscription(SignalBus signalBus, Action<SimpleUntargetedMessage> handler)
|
|
375
|
+
{
|
|
376
|
+
_signalBus = signalBus;
|
|
377
|
+
_handler = handler;
|
|
378
|
+
_signalBus.Subscribe(handler);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
public void Dispose()
|
|
382
|
+
{
|
|
383
|
+
if (_disposed)
|
|
384
|
+
{
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
_signalBus.TryUnsubscribe(_handler);
|
|
389
|
+
_disposed = true;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
#endif
|
|
394
|
+
}
|
|
395
|
+
}
|