Skip to content

Change Image (and other) messages to use byte[] rather than uint8[] #55

Open

Description

Change request

In the Image, CompressedImage, and PointCloud2 messages there are data fields that have type uint8[]. I suggest these are chaged to byte[].

Change description

According to the wiki, uint8 is interpreted as a python int, whereas byte is interpreted as a python byte. For the messages where arrays of uint8 are used, it's normally because the data is some arbitrary binary format. Currently, it seems that rclpy takes this binary data, copies it out into a list[int], which client code then normally converts back to some collection of byte types for use. This is much more processing and copying than is necessary.

This should also somewhat mitigate this issue, as no range check will be necessary.

Implementation considerations

I can think of no cons of this change

connects to ros2/rosidl#190

Activity

  1. mikaelarguedas commented on Aug 16, 2018

    @mikaelarguedas
    Member

    Implementation consideration: evaluate how this plays with current ROS1 serialization of these messages and detail potential additional work to be able to keep bridging such messages over the ros1_bridge

  2. sloretz commented on Aug 16, 2018

    @sloretz
    Contributor

    Related to ros2/rosidl#190

  3. kervel commented on Oct 4, 2018

    @kervel

    Hello,
    i think this would not be sufficient. even for byte[] the generated convert_to_py still creates a python List, see:
    https://github.com/ros2/rosidl_python/blob/master/rosidl_generator_py/resource/_msg_support.c.em#L339

    i tried to make a ByteImage (by copying Image and changing uint8 to byte) to get faster python IO but i still get a List in python..

    i think bytes --> byte[] is only for conversion from python, not conversion to python..;

    See also ros2/rosidl#276

    Frank

  4. kervel commented on Oct 5, 2018

    @kervel

    @johnmarkwayve indeed. i should check what exactly would be the gain, now i was under the assumption that most time would be spent in traversing linked lists (i'll try to find out).
    I was using the python bindings now to feed an image to a keras model, and while the keras model inference only takes 7msec, but the whole conversion from buffer to python linkedlist to buffer takes almost 40msec..

    Frank

  5. dirk-thomas commented on Oct 6, 2018

    @dirk-thomas
    Member

    In the scope of ros2/design#190 the mapping of char[] is defined as bytes in Python. Once that change has been rolled out the image message will be changed to use that type instead of uint8[].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions