Bird
Raised Fist0
ROSframework~8 mins

Marker display for custom visualization in ROS - Performance & Optimization

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Performance: Marker display for custom visualization
MEDIUM IMPACT
This affects the rendering speed and responsiveness of custom visual elements in ROS visualization tools like RViz.
Displaying multiple custom markers in RViz for real-time visualization
ROS
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)
Using a single Marker with SPHERE_LIST type batches all points into one draw call, reducing CPU/GPU overhead and improving frame rate.
📈 Performance GainSingle re-render per update, significantly smoother visualization and lower CPU usage.
Displaying multiple custom markers in RViz for real-time visualization
ROS
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)
Publishing a large number of individual markers every frame causes heavy CPU and GPU load, triggering frequent re-renders and slowing down visualization.
📉 Performance CostTriggers hundreds of re-renders per update, causing frame drops and input lag.
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Many individual markersHigh (1000+ nodes)High (hundreds per update)High (many draw calls)[X] Bad
Single SPHERE_LIST markerLow (1 node)Low (1 per update)Low (single draw call)[OK] Good
Rendering Pipeline
Marker data is sent from ROS nodes to RViz, which processes marker messages, calculates layout and style, then paints the markers on screen. Large numbers of markers or frequent updates increase layout and paint costs.
Layout
Paint
Composite
⚠️ BottleneckPaint stage is most expensive due to many draw calls for individual markers.
Core Web Vital Affected
INP
This affects the rendering speed and responsiveness of custom visual elements in ROS visualization tools like RViz.
Optimization Tips
1Batch multiple points into a single marker using list types to reduce draw calls.
2Avoid publishing thousands of individual markers every frame to prevent rendering lag.
3Limit marker update frequency to balance visualization freshness and performance.
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main performance issue when publishing thousands of individual markers separately in ROS visualization?
AToo few markers causing underutilization
BExcessive draw calls causing slow rendering
CMarkers not visible due to color settings
DNetwork bandwidth limits
DevTools: RViz Visualization Monitor / ROS Logging
How to check: Use RViz's built-in FPS display and CPU usage monitor while publishing markers; check ROS logs for message frequency.
What to look for: Low FPS and high CPU usage indicate poor marker performance; steady FPS and low CPU usage indicate good performance.

Practice

(1/5)
1. What is the main purpose of using markers in ROS visualization tools like RViz?
easy
A. To control the robot's movement directly
B. To send commands to the robot's motors
C. To draw shapes in 3D space to help visualize robot data
D. To store robot configuration files

Solution

  1. Step 1: Understand marker usage in ROS

    Markers are used to create visual shapes like arrows, cubes, or spheres in RViz to represent data.
  2. Step 2: Differentiate markers from control commands

    Markers do not control robot movement or store files; they only help visualize data.
  3. Final Answer:

    To draw shapes in 3D space to help visualize robot data -> Option C
  4. Quick Check:

    Markers visualize data = B [OK]
Hint: Markers show shapes for visualization, not control [OK]
Common Mistakes:
  • Thinking markers control robot movement
  • Confusing markers with configuration files
  • Assuming markers send commands to motors
2. Which of the following is the correct way to set the type of a marker to a sphere in ROS using the visualization_msgs/Marker message?
easy
A. marker.type = visualization_msgs::Marker::SPHERE;
B. marker.type = visualization_msgs::Marker::CUBE;
C. marker.type = visualization_msgs::Marker::LINE_STRIP;
D. marker.type = visualization_msgs::Marker::TEXT_VIEW_FACING;

Solution

  1. Step 1: Identify marker type constants

    ROS defines marker types like CUBE, SPHERE, LINE_STRIP, TEXT_VIEW_FACING as constants in visualization_msgs::Marker.
  2. Step 2: Match sphere type

    The constant for a sphere is visualization_msgs::Marker::SPHERE.
  3. Final Answer:

    marker.type = visualization_msgs::Marker::SPHERE; -> Option A
  4. Quick Check:

    SPHERE type constant = A [OK]
Hint: Use Marker::SPHERE constant to set sphere type [OK]
Common Mistakes:
  • Using CUBE instead of SPHERE
  • Confusing LINE_STRIP with sphere
  • Using text marker type for shapes
3. Given the following ROS Python code snippet, what will be the color of the marker displayed in RViz?
marker.color.r = 0.0
marker.color.g = 1.0
marker.color.b = 0.0
marker.color.a = 0.5
medium
A. Opaque red
B. Fully transparent (invisible)
C. Opaque blue
D. Semi-transparent green

Solution

  1. Step 1: Analyze RGB color values

    Red = 0.0, Green = 1.0, Blue = 0.0 means pure green color.
  2. Step 2: Check alpha (opacity) value

    Alpha = 0.5 means 50% transparency, so semi-transparent.
  3. Final Answer:

    Semi-transparent green -> Option D
  4. Quick Check:

    Green=1 and alpha=0.5 = D [OK]
Hint: Alpha <1 means transparency; RGB sets color [OK]
Common Mistakes:
  • Ignoring alpha and assuming opaque
  • Mixing up RGB values for color
  • Thinking alpha=0.5 means fully transparent
4. You wrote this ROS C++ code to publish a marker, but the marker does not appear in RViz. What is the likely error?
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);
medium
A. Incorrect marker type used
B. Missing setting of marker.header.stamp to current time
C. Scale values are too small to see
D. Color alpha is zero making it invisible

Solution

  1. Step 1: Check marker header completeness

    ROS markers require header.stamp to be set to current time for RViz to display them properly.
  2. Step 2: Verify other parameters

    Marker type, scale, and color are valid and visible; alpha is 1.0 (opaque).
  3. Final Answer:

    Missing setting of marker.header.stamp to current time -> Option B
  4. Quick Check:

    Header stamp missing = A [OK]
Hint: Always set header.stamp to ros::Time::now() [OK]
Common Mistakes:
  • Forgetting to set header.stamp
  • Using zero alpha making marker invisible
  • Assuming scale too small to see
5. You want to display multiple markers at different positions using a single ROS publisher. Which approach correctly updates and publishes markers to show all of them in RViz?
hard
A. Publish each marker separately with unique IDs and the same topic
B. Publish only the last marker repeatedly, ignoring others
C. Publish markers with the same ID to overwrite previous ones
D. Publish markers without setting frame_id to avoid errors

Solution

  1. Step 1: Understand marker IDs and topics

    Each marker must have a unique ID to be displayed simultaneously on the same topic.
  2. Step 2: Avoid overwriting markers

    Publishing markers with the same ID overwrites previous ones, so unique IDs are needed.
  3. Final Answer:

    Publish each marker separately with unique IDs and the same topic -> Option A
  4. Quick Check:

    Unique IDs per marker = C [OK]
Hint: Use unique IDs for each marker on one topic [OK]
Common Mistakes:
  • Using same ID for multiple markers
  • Publishing only one marker and expecting all to show
  • Not setting frame_id causing display errors