Conversation
|
Thanks for looking into this 🙂 Do you have more specifics on where the performance impact is coming from? From a usability perspective, it might be better to continue to use |
|
@jacobperron |
|
To clarify my previous comment, I do think that switching to Array in the C code makes sense, but my question is if it is necessary to also change all of the API in the Java client code? For example, I wouldn't think that changing the types used by the parameters API would have a significant performance impact on publishing and subscribing to image topics. I plan to investigate the performance issues myself and will give a more informed review later. |
| jobject _jlist_@(member.name)_element = env->NewObject( | ||
| _j@(normalized_type)_class_global, _j@(normalized_type)_constructor_global, _ros_@(member.name)_element); |
There was a problem hiding this comment.
IIUC, the performance issue is coming from creating new Java objects for each element in the list.
|
I haven't found a way to improve performance while continuing to use the sensor_msgs.msg.Image message = new sensor_msgs.msg.Image();
// Before
List<Byte> image_data = message.getData();
image_data.get(0); // access
image_data.add((byte) 200); // modify message
// After
byte[] image_data = message.getData();
image_data[0]; // access
// No easy way to modify message in place, must construct a new array
int[] new_image_data = Arrays.copyOf(image_data, image_data.length + 1);
new_image_data[arr.length] = (byte) 200;
message.setData(new_image_data);But, perhaps not being able to change the size of a ROS message in-place is a good thing. It might avoid bugs where the user modifies the returned list and unintentionally modifies the member of the message. @esteve Any thoughts on this? I think we really do need to address this performance issue. |
|
I think a good option is to switch to arrays by default and offer a convenience method for getting List types. I've adapted this PR with additional changes and fixes: https://github.com/osrf/ros2_java/tree/jacob/list_to_array I'll adapt it for |
|
Re-applying this change in #165. |
In JNI code, it has been modified from List to Array.
If there are need to be fix, please comment.
Issue : #149