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

fix(traffic_light): don't call addTrafficLight() when the traffic light id has already existed in map #1499

Merged
merged 4 commits into from
Jan 7, 2025

Conversation

satoshi-ota
Copy link
Contributor

@satoshi-ota satoshi-ota commented Dec 27, 2024

Description

The following function in traffic_light_base.cpp is quite heavy because it always tries adding traffic light even when the traffic light has been registered in simulator.

auto TrafficLightsBase::getTrafficLight(const lanelet::Id traffic_light_id) -> TrafficLight &
{
  addTrafficLight(traffic_light_id);
  return traffic_lights_map_.at(traffic_light_id);
}

As a result, it becomes a bottle neck of simulator when I write a code to update traffic light color frequently.

Screenshot from 2024-11-13 13-29-45

Abstract

I added the guard to prevent redundant process like this:

diff --git a/simulation/traffic_simulator/src/traffic_lights/traffic_lights_base.cpp b/simulation/traffic_simulator/src/traffic_lights/traffic_lights_base.cpp
index 48110784a..906e80258 100644
--- a/simulation/traffic_simulator/src/traffic_lights/traffic_lights_base.cpp
+++ b/simulation/traffic_simulator/src/traffic_lights/traffic_lights_base.cpp
@@ -123,6 +123,10 @@ auto TrafficLightsBase::addTrafficLight(const lanelet::Id traffic_light_id) -> v
 
 auto TrafficLightsBase::getTrafficLight(const lanelet::Id traffic_light_id) -> TrafficLight &
 {
+  if (isTrafficLightAdded(traffic_light_id)) {
+    return traffic_lights_map_.at(traffic_light_id);
+  }
+
   addTrafficLight(traffic_light_id);
   return traffic_lights_map_.at(traffic_light_id);
 }

Background

N/A

Details

With this PR, I confirmed the process load became light.

image

References

N/A

Destructive Changes

N/A

Known Limitations

N/A

Copy link

github-actions bot commented Dec 27, 2024

Checklist for reviewers ☑️

All references to "You" in the following text refer to the code reviewer.

  • Is this pull request written in a way that is easy to read from a third-party perspective?
  • Is there sufficient information (background, purpose, specification, algorithm description, list of disruptive changes, and migration guide) in the description of this pull request?
  • If this pull request contains a destructive change, does this pull request contain the migration guide?
  • Labels of this pull request are valid?
  • All unit tests/integration tests are included in this pull request? If you think adding test cases is unnecessary, please describe why and cross out this line.
  • The documentation for this pull request is enough? If you think adding documents for this pull request is unnecessary, please describe why and cross out this line.

@satoshi-ota satoshi-ota marked this pull request as ready for review December 27, 2024 04:34
@HansRobo HansRobo added the bump patch If this pull request merged, bump patch version of the scenario_simulator_v2 label Jan 6, 2025
Signed-off-by: satoshi-ota <[email protected]>
@HansRobo HansRobo merged commit f4469ad into master Jan 7, 2025
12 checks passed
@HansRobo HansRobo deleted the tmp/pc-patch branch January 7, 2025 07:59
@github-actions github-actions bot restored the tmp/pc-patch branch January 7, 2025 07:59
@github-actions github-actions bot deleted the tmp/pc-patch branch January 7, 2025 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bump patch If this pull request merged, bump patch version of the scenario_simulator_v2 wait for regression test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants