Skip to content

Potential clock duplication in TimeSource #2253

@luca-della-vedova

Description

@luca-della-vedova

Hello! I was working on an rcl client library and was using rclcpp (and rclpy) as reference implementation, and when working on TimeSource I found a potential issue.

Specifically, when looking at the TimeSource implementation for both rclpy and rclcpp, I noticed that for each time source, its associated clocks are stored in a vector.

Now apart from the premature-optimization-root-of-all-evil issue of having finds be linear in time here, I believe the fact that clocks are naively appended in attachClock would allow duplicates in the vector. Now the drawback is not the end of the world since it's just that the same clock would be updated more than once for each subscription callback but would it make sense to either:

  • Do an std::find call in attachClock and print a warning + avoid appending if the clock already exists
  • Make the attached clocks storage structure a unordered_set?

If any of these makes sense I'll be happy to open upstream PRs in both rclpy and rclcpp since they have the same implementation (rclpy is here)

Metadata

Metadata

Assignees

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