From 3e00876c0fc5caf13fca4957a8cf68da1bbf0534 Mon Sep 17 00:00:00 2001 From: Loretta Date: Wed, 8 Apr 2026 11:09:13 +0200 Subject: [PATCH] Increase default buffer size; remove diagnostic test/debug Increased InitialBufferCapacity default to 16 KB in AcBinarySerializerOptions and updated docs. Removed ProtocolRoundTripDiagnosticTest and related diagnostic code from SignalRClientToHubTest.cs. Cleaned up debug output in AcBinaryHubProtocol.cs by removing Debug.WriteLine statements. --- .../Binaries/AcBinarySerializerOptions.cs | 4 +-- AyCode.Core/docs/BINARY_OPTIONS.md | 2 +- .../SignalRs/SignalRClientToHubTest.cs | 28 ------------------- .../SignalRs/AcBinaryHubProtocol.cs | 2 -- 4 files changed, 3 insertions(+), 33 deletions(-) diff --git a/AyCode.Core/Serializers/Binaries/AcBinarySerializerOptions.cs b/AyCode.Core/Serializers/Binaries/AcBinarySerializerOptions.cs index dacc3db..7364c93 100644 --- a/AyCode.Core/Serializers/Binaries/AcBinarySerializerOptions.cs +++ b/AyCode.Core/Serializers/Binaries/AcBinarySerializerOptions.cs @@ -126,9 +126,9 @@ public sealed class AcBinarySerializerOptions : AcSerializerOptions /// /// Initial capacity for serialization buffer. - /// Default: 4096 bytes + /// Default: 16384 bytes (16 KB) /// - public int InitialBufferCapacity { get; init; } = 4096;d + public int InitialBufferCapacity { get; init; } = 16384; /// /// Chunk size (in bytes) used by when writing to an . diff --git a/AyCode.Core/docs/BINARY_OPTIONS.md b/AyCode.Core/docs/BINARY_OPTIONS.md index 07b2670..e0ed825 100644 --- a/AyCode.Core/docs/BINARY_OPTIONS.md +++ b/AyCode.Core/docs/BINARY_OPTIONS.md @@ -119,7 +119,7 @@ delegate PropertyInfo? PropertyMapperDelegate(PropertyInfo sourceProperty, Type | Option | Type | Default | Purpose | |--------|------|---------|---------| | `UseGeneratedCode` | bool | `true` | Use source-generated writers/readers when available. Enables SGen root fast path (see `BINARY_SGEN.md`) | -| `InitialBufferCapacity` | int | 4096 | Starting buffer size (bytes) for serialization output | +| `InitialBufferCapacity` | int | 16384 | Starting buffer size (bytes) for serialization output | | `RemoveOrphanedItems` | bool | `false` | During `PopulateMerge`: remove destination collection items with no matching source ID | | `UseAsync` | bool | `false` | Async context pool return via ThreadPool. Auto-disabled in WASM and when `ReferenceHandling=None` | | `MaxContextPoolSize` | int | 8 | Max serialization contexts kept in pool | diff --git a/AyCode.Services.Server.Tests/SignalRs/SignalRClientToHubTest.cs b/AyCode.Services.Server.Tests/SignalRs/SignalRClientToHubTest.cs index 86e804b..b224a71 100644 --- a/AyCode.Services.Server.Tests/SignalRs/SignalRClientToHubTest.cs +++ b/AyCode.Services.Server.Tests/SignalRs/SignalRClientToHubTest.cs @@ -1194,34 +1194,6 @@ public abstract class SignalRClientToHubTestBase /// /// Runs all SignalR tests with JSON serialization. /// -/// -/// Diagnostic test: isolates protocol round-trip from the full client-hub flow. -/// -[TestClass] -public class ProtocolRoundTripDiagnosticTest -{ - [TestMethod] - public void Protocol_RoundTrip_BasicInvocation() - { - var protocol = new AyCodeBinaryHubProtocol(); - var binder = new TestInvocationBinder(); - - var signalParams = new SignalParams { Status = SignalResponseStatus.Success }; - var invocation = new InvocationMessage( - nameof(IAcSignalRHubClient.OnReceiveMessage), - new object?[] { 42, (int?)1, signalParams, Array.Empty() }); - - var bytes = protocol.GetMessageBytes(invocation); - - // Diagnostic: dump first bytes - var arr = bytes.ToArray(); - var lengthPrefix = BitConverter.ToInt32(arr, 0); - var firstByte = arr.Length > 4 ? arr[4] : (byte)0; - - Assert.Fail($"Bytes={arr.Length}, LengthPrefix={lengthPrefix}, Remaining={arr.Length - 4}, " + - $"FirstPayloadByte=0x{firstByte:X2}, First16={BitConverter.ToString(arr, 0, Math.Min(16, arr.Length))}"); - } -} [TestClass] public class SignalRClientToHubTest_Json : SignalRClientToHubTestBase diff --git a/AyCode.Services/SignalRs/AcBinaryHubProtocol.cs b/AyCode.Services/SignalRs/AcBinaryHubProtocol.cs index 8c5d14e..8caea62 100644 --- a/AyCode.Services/SignalRs/AcBinaryHubProtocol.cs +++ b/AyCode.Services/SignalRs/AcBinaryHubProtocol.cs @@ -395,10 +395,8 @@ public class AcBinaryHubProtocol : IHubProtocol private void WriteArgument(ref BufferWriterBinaryOutput bw, IBufferWriter output, object? value, ref int externalBytes) { - Debug.WriteLine($"WriteArgument invoked"); if (value is byte[] byteArray) { - Debug.WriteLine($"WriteArgument value is byte[] byteArray"); // byte[] fast-path: size known upfront, write entirely through BWO var argPayload = 1 + VarUIntSize((uint)byteArray.Length) + byteArray.Length;