From d820427cb7406de274b2fde320db07cdc611f391 Mon Sep 17 00:00:00 2001 From: kosuke55 Date: Wed, 14 Aug 2024 15:06:21 +0900 Subject: [PATCH 1/2] perf(goal_planner): reduce unnecessary recursive lock guard Signed-off-by: kosuke55 --- .../goal_planner_module.hpp | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/include/autoware/behavior_path_goal_planner_module/goal_planner_module.hpp b/planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/include/autoware/behavior_path_goal_planner_module/goal_planner_module.hpp index 749ed57f95cc9..4b1ff273f3a99 100644 --- a/planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/include/autoware/behavior_path_goal_planner_module/goal_planner_module.hpp +++ b/planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/include/autoware/behavior_path_goal_planner_module/goal_planner_module.hpp @@ -143,6 +143,11 @@ class ThreadSafeData void set_pull_over_path(const PullOverPath & path) { const std::lock_guard lock(mutex_); + set_pull_over_path_no_lock(path); + } + + void set_pull_over_path_no_lock(const PullOverPath & path) + { pull_over_path_ = std::make_shared(path); if (path.type != PullOverPlannerType::NONE && path.type != PullOverPlannerType::FREESPACE) { lane_parking_pull_over_path_ = std::make_shared(path); @@ -154,6 +159,11 @@ class ThreadSafeData void set_pull_over_path(const std::shared_ptr & path) { const std::lock_guard lock(mutex_); + set_pull_over_path_no_lock(path); + } + + void set_pull_over_path_no_lock(const std::shared_ptr & path) + { pull_over_path_ = path; if (path->type != PullOverPlannerType::NONE && path->type != PullOverPlannerType::FREESPACE) { lane_parking_pull_over_path_ = path; @@ -165,16 +175,17 @@ class ThreadSafeData void set(Args... args) { std::lock_guard lock(mutex_); - (..., set(args)); + (..., set_no_lock(args)); } - void set(const GoalCandidates & arg) { set_goal_candidates(arg); } - void set(const std::vector & arg) { set_pull_over_path_candidates(arg); } - void set(const std::shared_ptr & arg) { set_pull_over_path(arg); } - void set(const PullOverPath & arg) { set_pull_over_path(arg); } - void set(const GoalCandidate & arg) { set_modified_goal_pose(arg); } - void set(const BehaviorModuleOutput & arg) { set_last_previous_module_output(arg); } - void set(const PreviousPullOverData & arg) { set_prev_data(arg); } - void set(const CollisionCheckDebugMap & arg) { set_collision_check(arg); } + + void set_no_lock(const GoalCandidates & arg) { goal_candidates_ = arg; } + void set_no_lock(const std::vector & arg) { pull_over_path_candidates_ = arg; } + void set_no_lock(const std::shared_ptr & arg) { set_pull_over_path_no_lock(arg); } + void set_no_lock(const PullOverPath & arg) { set_pull_over_path_no_lock(arg); } + void set_no_lock(const GoalCandidate & arg) { modified_goal_pose_ = arg; } + void set_no_lock(const BehaviorModuleOutput & arg) { last_previous_module_output_ = arg; } + void set_no_lock(const PreviousPullOverData & arg) { prev_data_ = arg; } + void set_no_lock(const CollisionCheckDebugMap & arg) { collision_check_ = arg; } void clearPullOverPath() { From 2589c6609388505a81b1eb43f4d59d13e6901b57 Mon Sep 17 00:00:00 2001 From: kosuke55 Date: Thu, 15 Aug 2024 12:58:12 +0900 Subject: [PATCH 2/2] make set_no_lock private Signed-off-by: kosuke55 --- .../goal_planner_module.hpp | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/include/autoware/behavior_path_goal_planner_module/goal_planner_module.hpp b/planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/include/autoware/behavior_path_goal_planner_module/goal_planner_module.hpp index 4b1ff273f3a99..aaad9d5f1a8f7 100644 --- a/planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/include/autoware/behavior_path_goal_planner_module/goal_planner_module.hpp +++ b/planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/include/autoware/behavior_path_goal_planner_module/goal_planner_module.hpp @@ -146,31 +146,12 @@ class ThreadSafeData set_pull_over_path_no_lock(path); } - void set_pull_over_path_no_lock(const PullOverPath & path) - { - pull_over_path_ = std::make_shared(path); - if (path.type != PullOverPlannerType::NONE && path.type != PullOverPlannerType::FREESPACE) { - lane_parking_pull_over_path_ = std::make_shared(path); - } - - last_path_update_time_ = clock_->now(); - } - void set_pull_over_path(const std::shared_ptr & path) { const std::lock_guard lock(mutex_); set_pull_over_path_no_lock(path); } - void set_pull_over_path_no_lock(const std::shared_ptr & path) - { - pull_over_path_ = path; - if (path->type != PullOverPlannerType::NONE && path->type != PullOverPlannerType::FREESPACE) { - lane_parking_pull_over_path_ = path; - } - last_path_update_time_ = clock_->now(); - } - template void set(Args... args) { @@ -178,15 +159,6 @@ class ThreadSafeData (..., set_no_lock(args)); } - void set_no_lock(const GoalCandidates & arg) { goal_candidates_ = arg; } - void set_no_lock(const std::vector & arg) { pull_over_path_candidates_ = arg; } - void set_no_lock(const std::shared_ptr & arg) { set_pull_over_path_no_lock(arg); } - void set_no_lock(const PullOverPath & arg) { set_pull_over_path_no_lock(arg); } - void set_no_lock(const GoalCandidate & arg) { modified_goal_pose_ = arg; } - void set_no_lock(const BehaviorModuleOutput & arg) { last_previous_module_output_ = arg; } - void set_no_lock(const PreviousPullOverData & arg) { prev_data_ = arg; } - void set_no_lock(const CollisionCheckDebugMap & arg) { collision_check_ = arg; } - void clearPullOverPath() { const std::lock_guard lock(mutex_); @@ -243,6 +215,34 @@ class ThreadSafeData DEFINE_SETTER_GETTER_WITH_MUTEX(PredictedObjects, dynamic_target_objects) private: + void set_pull_over_path_no_lock(const PullOverPath & path) + { + pull_over_path_ = std::make_shared(path); + if (path.type != PullOverPlannerType::NONE && path.type != PullOverPlannerType::FREESPACE) { + lane_parking_pull_over_path_ = std::make_shared(path); + } + + last_path_update_time_ = clock_->now(); + } + + void set_pull_over_path_no_lock(const std::shared_ptr & path) + { + pull_over_path_ = path; + if (path->type != PullOverPlannerType::NONE && path->type != PullOverPlannerType::FREESPACE) { + lane_parking_pull_over_path_ = path; + } + last_path_update_time_ = clock_->now(); + } + + void set_no_lock(const GoalCandidates & arg) { goal_candidates_ = arg; } + void set_no_lock(const std::vector & arg) { pull_over_path_candidates_ = arg; } + void set_no_lock(const std::shared_ptr & arg) { set_pull_over_path_no_lock(arg); } + void set_no_lock(const PullOverPath & arg) { set_pull_over_path_no_lock(arg); } + void set_no_lock(const GoalCandidate & arg) { modified_goal_pose_ = arg; } + void set_no_lock(const BehaviorModuleOutput & arg) { last_previous_module_output_ = arg; } + void set_no_lock(const PreviousPullOverData & arg) { prev_data_ = arg; } + void set_no_lock(const CollisionCheckDebugMap & arg) { collision_check_ = arg; } + std::shared_ptr pull_over_path_{nullptr}; std::shared_ptr lane_parking_pull_over_path_{nullptr}; std::vector pull_over_path_candidates_;