Skip to content

2.1: Value-type request elements (ReadValueId, WriteValue) to remove per-operation decode allocations #5208

Backlog

Description

@romanett

Summary

Make the per-operation request elements of the bulk services value types, starting with ReadValueId and WriteValue, so that decoding a request stops allocating one heap object per operation. After R0 (#5193) and R2 (#5207), these decoded elements are the largest allocation left on the server's Read and Write paths. Both are public classes in the request types, so this is a breaking API change and targets 2.1.

There is no change on the wire.

Measurement

Allocation traces with perf/ServerLoadHarness on master 8ecb5ec plus #5193 (.NET 10, managed client, 20 sessions). Shares are of all allocated bytes, by first Opc.Ua frame.

Scenario Object (request decoding) Share of bytes
read (100 nodes per request, about 200 B per value) ReadValueId 50.7 %
read ReadValueId[] 4.8 %
write-plain WriteValue 36 %

R2 (#5207) pools the Read result arrays, which cuts Read bytes per request by 30 %, from 19,954 to 13,960 B. After R2, ReadValueId is roughly 70 % of what remains. Reads have the highest GC pause of the scenarios in the load report, 400–450 ms per 15 s with the default GC.

#4779 tracks the other per-request allocations (pipeline objects, default headers, queue entries). This issue is only about the per-operation elements, which #4779 lists as "rest".

Proposal

  1. Turn ReadValueId and WriteValue into structs, or readonly record structs where practical. Decode them into an ArrayOf<T> / pooled array owned by the request.
  2. Move the server-side processing state out of the wire type. ReadValueId currently carries Handle, Processed and ParsedIndexRange (and WriteValue the same pattern), which node managers set while they process the request. Options:
    • a parallel per-operation state array owned by the request (preferred: the wire type stays immutable), or
    • keep the fields on the struct and pass elements by ref through the node manager APIs.
  3. Adapt the node manager surface (INodeManager/IAsyncNodeManager Read/Write, MasterNodeManager, CustomNodeManager2, AsyncCustomNodeManager, fluent node managers) and the client APIs that build these lists, keeping ergonomic builders for client code.
  4. Once the pattern is settled, consider the same change for the other bulk-service elements: BrowseDescription, CallMethodRequest, MonitoredItemCreateRequest/ModifyRequest, HistoryReadValueId.

Risks / open questions

  • Public API break for every custom node manager and for client code that builds or mutates request lists. Needs a migration note and probably analyzer guidance.
  • Null semantics: a null element currently decodes to BadStructureMissing in ReadValueId.Validate. A struct needs an explicit "missing" representation, or the decoder handles that case.
  • Copy cost: WriteValue carries a DataValue. Struct elements must be passed by ref/in on hot paths so that copies don't eat the gain.
  • Generated code: the types are partially generated, so the source generator needs a way to emit selected structures as value types.

Success criteria

  • Server read and write-plain bytes per request fall by about the share above, with no throughput or CPU regression, measured with the paired A/B harness.
  • No per-operation heap object left in request decoding for the converted services.

🤖 Generated with Claude Code

Activity

  1. added
    enhancement
    2.1
    on Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    2.1enhancementperformance

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions