Performance: Marker display for custom visualization
This affects the rendering speed and responsiveness of custom visual elements in ROS visualization tools like RViz.
Jump into concepts and practice - no test required
marker = Marker() marker.id = 0 marker.type = Marker.SPHERE_LIST marker.points = [Point(x=i*0.1, y=0, z=0) for i in range(1000)] marker.scale.x = 0.1 marker.scale.y = 0.1 marker.scale.z = 0.1 marker.color.a = 1.0 marker.color.r = 1.0 publisher.publish(marker)
for i in range(1000): marker = Marker() marker.id = i marker.type = Marker.SPHERE marker.pose.position.x = i * 0.1 marker.pose.position.y = 0 marker.pose.position.z = 0 marker.scale.x = 0.1 marker.scale.y = 0.1 marker.scale.z = 0.1 marker.color.a = 1.0 marker.color.r = 1.0 marker_array.markers.append(marker) publisher.publish(marker_array)
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Many individual markers | High (1000+ nodes) | High (hundreds per update) | High (many draw calls) | [X] Bad |
| Single SPHERE_LIST marker | Low (1 node) | Low (1 per update) | Low (single draw call) | [OK] Good |
marker.color.r = 0.0 marker.color.g = 1.0 marker.color.b = 0.0 marker.color.a = 0.5
visualization_msgs::Marker marker; marker.header.frame_id = "map"; marker.type = visualization_msgs::Marker::SPHERE; marker.action = visualization_msgs::Marker::ADD; marker.pose.position.x = 1.0; marker.pose.position.y = 2.0; marker.pose.position.z = 0.0; marker.scale.x = 0.5; marker.scale.y = 0.5; marker.scale.z = 0.5; marker.color.r = 1.0; marker.color.g = 0.0; marker.color.b = 0.0; marker.color.a = 1.0; marker_pub.publish(marker);