Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: use single TF listener & add singleton #5

Conversation

amadeuszsz
Copy link
Collaborator

Description

  • Reduce temporary TF listeners from two to one.
  • Use singleton pattern for core implementation.

Tests performed

Not applicable.

Effects on system behavior

Not applicable.

Pre-review checklist for the PR author

The PR author must check the checkboxes below when creating the PR.

In-review checklist for the PR reviewers

The PR reviewers must check the checkboxes below before approval.

Post-review checklist for the PR author

The PR author must check the checkboxes below before merging.

  • There are no open discussions or they are tracked via tickets.

After all checkboxes are checked, anyone who has write access can merge the PR.

@amadeuszsz amadeuszsz added the enhancement New feature or request label Feb 25, 2025
@amadeuszsz amadeuszsz self-assigned this Feb 25, 2025
Signed-off-by: Amadeusz Szymko <[email protected]>
Copy link

codecov bot commented Feb 25, 2025

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Clang-Tidy found issue(s) with the introduced code (1/2)

Eigen::Matrix4f eigen_base_to_lidar_top_;
Eigen::Matrix4f eigen_base_to_lidar_right_;
std::unique_ptr<sensor_msgs::msg::PointCloud2> cloud_in_;
std::unique_ptr<sensor_msgs::msg::PointCloud2> cloud_in_{nullptr};
double precision_;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ cppcoreguidelines-pro-type-member-init ⚠️
constructor does not initialize these fields: precision_

Suggested change
double precision_;
double precision_{};

double precision_;
rclcpp::Time time_;
rclcpp::Duration timeout_ = rclcpp::Duration::from_seconds(1);

geometry_msgs::msg::TransformStamped generateTransformMsg(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-identifier-naming ⚠️
invalid case style for function generateTransformMsg

Suggested change
geometry_msgs::msg::TransformStamped generateTransformMsg(
geometry_msgs::msg::TransformStamped generate_transform_msg(


tf_map_to_base_ = generateTransformMsg(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-identifier-naming ⚠️
invalid case style for function generateTransformMsg

Suggested change
tf_map_to_base_ = generateTransformMsg(
tf_map_to_base_ = generate_transform_msg(


tf_map_to_base_ = generateTransformMsg(
10, 100'000'000, "map", "base_link", 120.0, 240.0, 1.0, 0.0, 0.0, 0.0, 1.0);
tf_base_to_lidar_top_ = generateTransformMsg(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-identifier-naming ⚠️
invalid case style for function generateTransformMsg

Suggested change
tf_base_to_lidar_top_ = generateTransformMsg(
tf_base_to_lidar_top_ = generate_transform_msg(


tf_map_to_base_ = generateTransformMsg(
10, 100'000'000, "map", "base_link", 120.0, 240.0, 1.0, 0.0, 0.0, 0.0, 1.0);
tf_base_to_lidar_top_ = generateTransformMsg(
10, 100'000'000, "base_link", "lidar_top", 0.690, 0.000, 2.100, -0.007, -0.007, 0.692, 0.722);
tf_base_to_lidar_right_ = generateTransformMsg(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-identifier-naming ⚠️
invalid case style for function generateTransformMsg

Suggested change
tf_base_to_lidar_right_ = generateTransformMsg(
tf_base_to_lidar_right_ = generate_transform_msg(

@@ -69,23 +72,45 @@
return tf_msg;
}

void broadcastDynamicTf(geometry_msgs::msg::TransformStamped transform, uint32_t seconds = 1)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-identifier-naming ⚠️
invalid case style for function broadcastDynamicTf

Suggested change
void broadcastDynamicTf(geometry_msgs::msg::TransformStamped transform, uint32_t seconds = 1)
void broadcast_dynamic_tf(geometry_msgs::msg::TransformStamped transform, uint32_t seconds = 1)

static_tf_broadcaster_->sendTransform(tf_base_to_lidar_right_);

std::future<void> future =
std::async(std::launch::async, [this]() { broadcastDynamicTf(tf_map_to_base_); });

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-identifier-naming ⚠️
invalid case style for function broadcastDynamicTf

Suggested change
std::async(std::launch::async, [this]() { broadcastDynamicTf(tf_map_to_base_); });
std::async(std::launch::async, [this]() { broadcast_dynamic_tf(tf_map_to_base_); });

ASSERT_TRUE(eigen_transform.has_value());
EXPECT_TRUE(eigen_transform.value().isApprox(eigen_base_to_lidar_top_, precision_));

std::future<void> future =
std::async(std::launch::async, [this]() { broadcastDynamicTf(tf_map_to_base_); });

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-identifier-naming ⚠️
invalid case style for function broadcastDynamicTf

Suggested change
std::async(std::launch::async, [this]() { broadcastDynamicTf(tf_map_to_base_); });
std::async(std::launch::async, [this]() { broadcast_dynamic_tf(tf_map_to_base_); });

@@ -69,23 +72,45 @@
return tf_msg;
}

void broadcastDynamicTf(geometry_msgs::msg::TransformStamped transform, uint32_t seconds = 1)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ performance-unnecessary-value-param ⚠️
the parameter transform is copied for each invocation but only used as a const reference; consider making it a const reference

Suggested change
void broadcastDynamicTf(geometry_msgs::msg::TransformStamped transform, uint32_t seconds = 1)
void broadcastDynamicTf(const geometry_msgs::msg::TransformStamped& transform, uint32_t seconds = 1)

#include <atomic>
#include <cstdint>
#include <future>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ modernize-pass-by-value ⚠️
pass by value and use std::move

Suggested change
#include <utility>

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Clang-Tidy found issue(s) with the introduced code (2/2)


ManagedTransformBufferProvider::ManagedTransformBufferProvider(
rclcpp::Clock::SharedPtr clock, tf2::Duration cache_time)
: clock_(clock)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ modernize-pass-by-value ⚠️
pass by value and use std::move

Suggested change
: clock_(clock)
: clock_(std::move(clock))

}
}

TraverseResult ManagedTransformBufferProvider::traverseTree(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-function-cognitive-complexity ⚠️
function traverseTree has cognitive complexity of 38 (threshold 25)

{
std::atomic<bool> timeout_reached{false};

auto framesToRoot = [this](

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-identifier-naming ⚠️
invalid case style for variable framesToRoot

Suggested change
auto framesToRoot = [this](
auto frames_to_root = [this](

return true;
};

auto traverse = [this, &timeout_reached, &framesToRoot](

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-identifier-naming ⚠️
invalid case style for variable framesToRoot

Suggested change
auto traverse = [this, &timeout_reached, &framesToRoot](
auto traverse = [this, &timeout_reached, &frames_to_root](

Comment on lines +220 to +221
!framesToRoot(t1, last_tf_tree, frames_from_t1) ||
!framesToRoot(t2, last_tf_tree, frames_from_t2)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-identifier-naming ⚠️
invalid case style for variable framesToRoot

Suggested change
!framesToRoot(t1, last_tf_tree, frames_from_t1) ||
!framesToRoot(t2, last_tf_tree, frames_from_t2)) {
!frames_to_root(t1, last_tf_tree, frames_from_t1) ||
!frames_to_root(t2, last_tf_tree, frames_from_t2)) {

explicit ManagedTransformBuffer(rclcpp::Node * node, bool managed = true);
explicit ManagedTransformBuffer(
rclcpp::Clock::SharedPtr clock,
tf2::Duration cache_time = tf2::Duration(tf2::BUFFER_CORE_DEFAULT_CACHE_TIME));

/** @brief Destroy the Managed Transform Buffer object */
~ManagedTransformBuffer();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ performance-trivially-destructible ⚠️
class ManagedTransformBuffer can be made trivially destructible by defaulting the destructor on its first declaration

Suggested change
~ManagedTransformBuffer();
~ManagedTransformBuffer() = default;

deactivateListener();
deactivateLocalListener();
}
ManagedTransformBuffer::~ManagedTransformBuffer() = default;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ performance-trivially-destructible ⚠️
class ManagedTransformBuffer can be made trivially destructible by defaulting the destructor on its first declaration

Suggested change
ManagedTransformBuffer::~ManagedTransformBuffer() = default;

@amadeuszsz amadeuszsz merged commit c4b97f6 into autowarefoundation:main Feb 25, 2025
15 of 16 checks passed
@amadeuszsz amadeuszsz deleted the perf/single-listener-with-singleton branch February 25, 2025 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant