AyCode.Core/AyCode.Services/SignalRs
Loretta 05808d0d13 SignalR: Add raw byte[] fast-path for DataSource GetAll
Implements a high-performance raw byte[] protocol path for SignalR DataSource GetAll/LoadDataSource, using a new IsRawBytesData flag in SignalParams. When enabled, the server pre-serializes response data and sends it as a byte array, which the protocol passes through without further (de)serialization. The client receives the raw bytes and deserializes as needed, avoiding double serialization/deserialization and improving performance for large payloads.

Adds SerializerType selection to DataSource, propagates SignalParams through hub and protocol layers, and updates client/server/test code to support the new path. Also includes diagnostics flags for binary serialization debugging and fixes for multi-segment buffer handling.
2026-04-07 00:20:52 +02:00
..
AcBinaryHubProtocol.cs SignalR: Add raw byte[] fast-path for DataSource GetAll 2026-04-07 00:20:52 +02:00
AcSignalRClientBase.cs SignalR: Add raw byte[] fast-path for DataSource GetAll 2026-04-07 00:20:52 +02:00
AcSignalRTags.cs Refactor JSON/SignalR infra; add full test & benchmark suite 2025-12-11 21:25:50 +01:00
AyCodeBinaryHubProtocol.cs Zero-copy SignalR: direct object response, no SignalData 2026-04-06 22:45:00 +02:00
IAcSignalRHubBase.cs Zero-copy SignalR: direct object response, no SignalData 2026-04-06 22:45:00 +02:00
IAcSignalRHubClient.cs Zero-copy SignalR: direct object response, no SignalData 2026-04-06 22:45:00 +02:00
ISignalParams.cs SignalR: Add raw byte[] fast-path for DataSource GetAll 2026-04-07 00:20:52 +02:00
README.md Switch SignalR payloads to ArrayPool-backed SignalData 2026-04-06 11:17:02 +02:00
SendToClientType.cs SignalR improvements; 2025-10-30 14:55:47 +01:00
SignalMessageTagAttribute.cs SignalR improvements; 2025-10-30 14:55:47 +01:00
SignalRCrudTags.cs improvements, fixes 2024-06-09 11:13:23 +02:00
SignalRRequestModel.cs Fix binary deserializer string interning and add regressions 2025-12-13 00:12:21 +01:00
SignalRSerializationHelper.cs Zero-copy SignalR: direct object response, no SignalData 2026-04-06 22:45:00 +02:00

README.md

SignalRs

Custom binary SignalR protocol, client infrastructure, message tagging, and serialization helpers.

Architecture: For full dispatch flow, tag system, and tech debt documentation see AyCode.Services/docs/SIGNALR.md. Binary protocol: For wire format, zero-copy pipeline, and dual BWO pattern see AyCode.Services/docs/SIGNALR_BINARY_PROTOCOL.md.

Key Files

Protocol

  • AcBinaryHubProtocol.cs — Unsealed base IHubProtocol replacing JSON+Base64 with AcBinarySerializer. Handles all 9 SignalR message types. Uses BufferWriterBinaryOutput standalone mode for zero-copy writes. byte[]/SignalData fast-path bypasses serializer. CreateByteArrayResult virtual hook for derived protocols. Inner SpanReader ref struct for zero-alloc parsing.
  • AyCodeBinaryHubProtocol.cs — Derived protocol. Overrides CreateByteArrayResult to rent from ArrayPool when targetType == typeof(SignalData). Register this instead of AcBinaryHubProtocol.
  • SignalData.csIDisposable wrapper for byte[] with optional ArrayPool lifecycle. Span for zero-copy access, Dispose() returns rented buffer. Created by AyCodeBinaryHubProtocol (pooled) or directly from byte[] (server send).

Client

  • AcSignalRClientBase.cs — Abstract SignalR client managing HubConnection, request/response tracking via pooled SignalRRequestModel. Methods: SendMessageToServerAsync<TResponse>(), CRUD helpers (Post, Get, GetAll, GetAllInto). Configurable timeouts.
  • IAcSignalRHubClient.cs — Client interface + SignalResponseDataMessage (sealed, ResponseData is SignalData?, supports JSON/Binary with GZip, caching, diagnostics, Dispose() returns buffers to ArrayPool).
  • IAcSignalRHubBase.cs — Base hub interface: OnReceiveMessage(int messageTag, int? requestId, SignalParams signalParams, SignalData data).
  • ISignalParams.csISignalParams base interface + SignalParams (Status, DataSerializerType, Parameters byte[]?). Metadata travels as separate hub argument (AcBinary serialized), payload SignalData uses protocol fast-path (ArrayPool-backed). Parameters and data are independent — both nullable in any direction.

Message Tagging

  • SignalMessageTagAttribute.cs — Three attributes: TagAttribute (base, int messageTag), SignalRAttribute (server method routing + client notification), SignalRSendToClientAttribute (client-side receive).
  • AcSignalRTags.cs — Static constants: None, PingTag, EchoTag.
  • SignalRCrudTags.cs — Sealed class bundling 5 independent CRUD tag integers. GetMessageTagByTrackingState() maps TrackingState -> tag. See AyCode.Services.Server/docs/SIGNALR_DATASOURCE.md.
  • SendToClientType.cs — Enum: None, Others, Caller, All.

Serialization & Pooling

  • SignalRSerializationHelper.cs — Static helpers: SerializeToBinary(), DeserializeFromBinary(), compressed JSON variants, CreateResponseData().
  • SignalRRequestModel.cs — Poolable (IResettable) request tracking model with ObjectPool for reuse.