perf(opcua-acl): #1033 flag-off revalidation answers local items before the pass memo
With Security:Acl:Enabled=false a revalidation pass over local Raw/UNS items is an unconditional allow; it still paid a (session, ns, id) memo entry and the full Permits walk per item. Measured over 10k items: ~6.5-7 ms and ~1.4 MB per pass -> ~0.5-1 ms and ~0.2 KB. IsLocalNodeUngated mirrors exactly what Permits concludes there and excludes the one wiring where it differs (mapped resolver without the projected predicate). The same shortcut inside the per-request Permits was measured and NOT taken: a 1,000-node flag-off Read stayed ~1.5-1.9 ms either way (SDK read dominates). Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -6286,6 +6286,29 @@ public sealed partial class OtOpcUaNodeManager : CustomNodeManager2, INodeManage
|
||||
(_authorizer is not null || _mappedSubjectResolver is null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// #1033: whether the revalidation pass's <c>CreateMonitoredItems</c> verdict on <paramref name="nodeId"/> is an
|
||||
/// unconditional allow — the node is in this manager's own Raw or UNS namespace and <c>Security:Acl:Enabled</c> is
|
||||
/// off. That is exactly what <see cref="Permits"/> concludes there for a non-Browse operation, minus its lookups:
|
||||
/// the imported-condition classifier answers only namespace [4], the projected predicate
|
||||
/// (<see cref="IsProjectedDescendant"/>) only [2]/[3], and <c>AuthorizeIfRequired</c> then takes the
|
||||
/// <c>localBypass</c>. The one wiring where the full path differs — a mapped-subject resolver with no projected
|
||||
/// predicate, which asks the resolver about every node and denies the local ones it cannot place — is excluded, so
|
||||
/// that configuration keeps its existing verdict.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Measured (10k flag-off items): a pass went from ~6.5–7 ms and ~1.4 MB (the pass-local memo's tuple keys and
|
||||
/// dictionary growth, plus the per-item authorizer walk) to ~0.5–1 ms and ~0.2 KB. The same shortcut in
|
||||
/// <see cref="Permits"/> itself was measured too and NOT taken: a 1,000-node flag-off Read stayed ~1.5–1.9 ms either
|
||||
/// way (the SDK read dominates).
|
||||
/// </remarks>
|
||||
/// <param name="nodeId">The target node.</param>
|
||||
/// <returns><see langword="true"/> when the decision is an allow without consulting the authorizer.</returns>
|
||||
private bool IsLocalNodeUngated(NodeId nodeId) =>
|
||||
_authorizer is { Enabled: false } authorizer
|
||||
&& (nodeId.NamespaceIndex == NamespaceIndexes[0] || nodeId.NamespaceIndex == NamespaceIndexes[1])
|
||||
&& (authorizer.MappedSubjectResolver is null || authorizer.MappedNamespacePredicate is not null);
|
||||
|
||||
/// <summary>Guard against a corrupt (cyclic) parent chain in <see cref="ResolveUnsAclSubject"/>.</summary>
|
||||
private const int MaxUnsAncestry = 64;
|
||||
|
||||
@@ -9290,6 +9313,9 @@ public sealed partial class OtOpcUaNodeManager : CustomNodeManager2, INodeManage
|
||||
// `Security:Acl:Enabled=false` bypass (AuthorizeIfRequired), the mapped/imported classifiers, and the
|
||||
// no-authorizer case. The bypass-less `IsAllowedCached` used here before enforced grants with the flag off,
|
||||
// standing every ungranted subscription (Anonymous included) down on the next tick or deploy.
|
||||
// #1033: the flag-off answer for a local node needs no memo entry (the tuple key + dictionary growth were most of a
|
||||
// 10k-item pass's ~1.4 MB / ~43 ms).
|
||||
if (IsLocalNodeUngated(nodeId)) return true;
|
||||
if (identity is null
|
||||
|| (identity.ApiKeyId ?? identity.Principal) is not { Length: > 0 } sessionKey
|
||||
|| !nodeId.TryGetValue(out string identifier) || identifier.Length == 0)
|
||||
|
||||
Reference in New Issue
Block a user