Hi all,
With rosidl::Buffer backends arriving in Lyrical, the recorder faces an issue: ros2 bag record only accepts the cpu backend, so every publisher converts its buffers to CPU memory and serializes them inside publish(), just because a recorder is subscribed. This prototype lets the recorder accept a backend and does that work on its own thread instead.
What it does
- Two opt-in options,
--acceptable-buffer-backends(defaultcpu, so nothing changes) and--buffer-aware-topics, also available as node parameters and inrosbag2_py. - A subscription that takes messages through the typed path and serializes them on the recorder’s side. A generic subscription cannot do this, because rmw_fastrtps deliberately rejects serialized takes of backend messages. The bag format and stored bytes are the same as before.
- An unknown backend name fails at startup and lists the installed backends.
- A message whose backend buffer arrives empty is dropped, counted as lost and logged, instead of being written as a valid-looking empty message.
Numbers
CUDA publisher, 1920x1080 sensor_msgs/Image at 30 Hz, RTX 3060: publish() goes from about 4.6 to 6 ms to 0.14 ms. The recorded messages are identical to the CPU path.
Testing it out
Branch (based on rolling): GitHub - UseTheForce007/rosbag2 at UseTheForce007/buffer-backend-recording · GitHub
ros2 bag record -s mcap -o my_bag --acceptable-buffer-backends any --topics /my_cuda_image
Caveats
- The recorder cannot see which backend a publisher uses (no public rmw/rclcpp API for it), so
--buffer-aware-topicsis a manual list. Types without arosidl::Bufferfield automatically keep the cheaper generic subscription. - Conversion runs on one executor thread, so a recorder with several 4K streams at 30 Hz can fall behind. A worker pool is a follow-up.
- Only the CUDA backend has been tested on hardware.
I’d love to hear back from the community if it’s useful and if there’s any bugs I might have overlooked.