From 7694eb67b201dff73e424539c800f366dd37569c Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Tue, 24 Nov 2026 14:56:49 -0500 Subject: [PATCH] =?UTF-8?q?perf(grpc-data):=20A2=20review=20N3=20=E2=80=94?= =?UTF-8?q?=20a=20caught-up=20hub=20reader=20skips=20the=20partition=20sca?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ConditionStateHub.Read scanned the whole partition under its gate on every tick even when the cursor was at the tail. The partition now records its tail version; a reader at or past it returns empty. --- .../DataConnections/ConditionStateHub.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/ConditionStateHub.cs b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/ConditionStateHub.cs index 2f86912b7..7e6bc3a53 100644 --- a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/ConditionStateHub.cs +++ b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/ConditionStateHub.cs @@ -49,6 +49,8 @@ public sealed class ConditionStateHub : IConditionStateSink public readonly object Gate = new(); public readonly Queue Buffer = new(); public long Floor; + /// The version of the newest buffered record (A2 review N3: a caught-up reader skips the scan). + public long Tail; } private readonly Partition[] _partitions; @@ -111,6 +113,7 @@ public sealed class ConditionStateHub : IConditionStateSink } p.Buffer.Enqueue(record with { Version = version }); + p.Tail = version; return version; } } @@ -154,6 +157,8 @@ public sealed class ConditionStateHub : IConditionStateSink lock (p.Gate) { if (afterVersion < p.Floor) return new ConditionDeltaRead(true, p.Floor, []); + // A2 review N3: a reader at or past the tail has nothing to read — never scan the partition under its gate. + if (afterVersion >= p.Tail) return new ConditionDeltaRead(false, p.Floor, []); var records = new List(); foreach (var r in p.Buffer) {