Performance improvements in datachange callbacks #1632
erogulenko
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there,
With increasing number of nodes in a server and a lot of value changes in short times, the performance of the MonitoredItemService.datachange_callback starts to matter quite a bit.
I looked into the implementation and would like to suggest minor improvements regarding performance.
First and most importantly, when calling MonitoredItemValues.set_current_datavalue() a deepcopy is performed on the DataValue instance. However, the DataValue itself and its fields are frozen dataclasses and therefore immutable, if I'm not mistaken. Only the DataValue.Value.Value which is the user value can be a mutable object. So my suggestion here would be, to only execute the deepcopy if the DataValue.Value.Value is not an instance of an immutable object, and only executing it on the DataValue.Value.Value itself and creating a new DataValue manually. Something like the following:
The isinstance check increases the function time by a bit for actually mutable objects, however, it saves a lot when the values are immutable with respect to just calling deepcopy on the immutable value.
If it's not desired to do this kind of isinstance check, just deepcopying the DataValue.Value.Value instead of the DataValue already leads to quite substantial performance improvements here.
Secondly, a minor improvement, in the MonitoredItemService.datachange_callback, the MonitoredItemNotification is generated each callback, even if the deadband_flag_pass is not passed and no event is being enqueued. This can be improved by just instantiating the MonitoredItemNotification directly before the enqueuing of the event.
These are just two suggestions on where to improve. If I'm mistaken in any of my assumptions, feel free to correct me.
Does anyone have other ideas on where we could improve performance further?
With the code changes above, I ran the unit tests from v1.1.0, which seem to be working the same as before those changes. So if the changes are OK from your end, I could create a pull request.
Beta Was this translation helpful? Give feedback.
All reactions