Repository navigation
Description
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
- Turn
ReadValueIdandWriteValueintostructs, orreadonly record structs where practical. Decode them into anArrayOf<T>/ pooled array owned by the request. - Move the server-side processing state out of the wire type.
ReadValueIdcurrently carriesHandle,ProcessedandParsedIndexRange(andWriteValuethe 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
refthrough the node manager APIs.
- Adapt the node manager surface (
INodeManager/IAsyncNodeManagerRead/Write,MasterNodeManager,CustomNodeManager2,AsyncCustomNodeManager, fluent node managers) and the client APIs that build these lists, keeping ergonomic builders for client code. - 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
nullelement currently decodes toBadStructureMissinginReadValueId.Validate. A struct needs an explicit "missing" representation, or the decoder handles that case. - Copy cost:
WriteValuecarries aDataValue. Struct elements must be passed byref/inon 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
readandwrite-plainbytes 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