nauful / LibUA

Open-source OPC UA client and server library
Apache License 2.0
262 stars 94 forks source link

OPC-UA Spec has a number of 'null' NodeId values. #170

Closed bevanweiss closed 5 months ago

bevanweiss commented 5 months ago

This Null NodeID PR didn't have the issue that the socket->stream change had. It also aligns compliance to OPC-UA spec better, so would be good to get in.

This introduces a Unit Test to prove the current deficiency, and to validate the change corrects the issue.

Have also added a Benchmark project, which has been used to investigate allocation sizes/performance of the NodeId type.

Have consolidated String/ByteArray(Guid/Opaque) reference type to a common 'object' field, but left accessor properties for the Byte/String types. I think the boxing/unboxing required for the NumericIdentifier would limit any benefit in doing similar with this type.

Also changed the enum base type for the NodeIdNetType to byte.

The combination of these took NodeId from 56 bytes down to 40bytes, and allocation of 1Million NodeIds from 74ms down to 55ms.

Changed the string comparison for NodeId equivalency to align with Microsoft best-practises https://learn.microsoft.com/en-us/dotnet/standard/base-types/best-practices-strings

Benchmark results, before robust null checks: |------------------ |--------------:|--------------:|--------------:|------------:| | NodeIdEquivalency | 8.142 us | 0.0917 us | 0.0766 us | 80.91 KB | | NodeIdAllocations | 76,750.335 us | 1,395.5669 us | 1,237.1337 us | 46875.56 KB |

and Benchmark results after the changes Method Mean Error StdDev Allocated
NodeIdEquivalency 9.376 us 0.1679 us 0.2564 us 80.16 KB
NodeIdAllocations 56,657.545 us 995.4564 us 931.1505 us 39062.95 KB