Skip to content

Commit 131ad8c

Browse files
helmut-jacoboroulet
authored andcommitted
Reuse the same Variant(None) on emitting events for non-existant fields
Clients registering for multiple event types will usually construct a select clause selecting _all_ fields of all subscribed events. For example when subscribing for all events in server-events.py with UaExport causes a ~200 field select clause. When triggering an event we walk all requested fields in the select clause (even though the event being triggered right now only has a few of them). In the server-events.py example this behavior causes quite some overhead as from the ~200 requested fields only a few need to be populated. For all other items a Variant(None) is instantiated. Instead of instantiating a new Variant(None) for every none-existant field we can just reuse the same instance for all none existant fields. In my tests this caused a speed up >50% (~5ms -> ~2ms) for triggering an event if a client with a large select clause is subscribed.
1 parent d92ad54 commit 131ad8c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

opcua/common/events.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def to_event_fields(self, select_clauses):
8181
"""
8282
return a field list using a select clause and the object properties
8383
"""
84+
none_field = ua.Variant(None, ua.VariantType.Null)
8485
fields = []
8586
for sattr in select_clauses:
8687
if not sattr.BrowsePath:
@@ -90,7 +91,7 @@ def to_event_fields(self, select_clauses):
9091
try:
9192
val = getattr(self, name)
9293
except AttributeError:
93-
field = ua.Variant(None)
94+
field = none_field
9495
else:
9596
field = ua.Variant(copy.deepcopy(val), self.data_types[name])
9697
fields.append(field)

0 commit comments

Comments
 (0)