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.
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.
References
N/A
Destructive Changes
N/A
Known Limitations
N/A