Hi everyone, I'm having some performance issues when trying to convert a dynamic_data array values to a list in python (see code below). Is there a better/more efficient way to do it? I'm using this rti python library: https://github.com/rticommunity/connextdds-py, https://community.rti.com/static/documentation/connext-dds/6.0.1/api/connext_dds/api_python/rti.html
array_info = []
if dynamic_data.member_info(i).kind == dds.TypeKind.ARRAY_TYPE:
array_data = dynamic_data.get_value(i)
for j in range(array_data.member_count):
array_info.append(array_data[j])
Does the following give you any improvement in performance?
if dynamic_data.member_info(i).kind == dds.TypeKind.ARRAY_TYPE:
array_info = list(dynamic_data[i])
yes, it does help on reducing to 1/3 of the time. Thank you very much. Can this also be used with arrays of enums(dds.TypeKind.ENUMERATION_TYPE)?
Yes, but there are some performance implications for that case. The returned sequence contains DynamicData EnumMember objects, which allows you to do things like print the string representation of the value. If you just want the ordinals you can use
list(sample.get_uint32_values(i))
which will be fasterHey Marc,
Thanks for your previous comment. I'm still not getting the performance I needed. I notice that calling dynamic_data.get_value(i) or array_data.member_info(i).kind take around 20 millisecond each. Is that the performance you normally get?
These two rti_dds calls are taking most of the time from my code. I attached the complete function so you can take a look at it, it is a recursive function. Maybe there is other places also to optimize.
I'm open to any suggestions.
Thanks in advance.
Accessing nested DynamicData structures can get expensive without loaning because it will create a copy. The following might yield a signficant increase in performance:
thanks Marc, for taking the time to look at the code and modify it. It works pretty nice.