maliput / maliput_sparse

A maliput backed capable of modeling RoadNetworks from waypoints.
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Meshes creation taking a lot of time for this map #47

Closed francocipollone closed 1 year ago

francocipollone commented 1 year ago

Summary

Using maliput_osm I measured how much time it takes to convert to obj the following map:

lanelet2_s_shape_road.zip image

Note: I noticed it because of using maliput_viz for checking out the maps.

franco@99dd75403bcd:~/maliput_ws_focal$ time maliput_to_obj --maliput_backend=osm --osm_file=zlanelet2_maps_scripts/lanelet2_s_shape_superelevated_road.osm
[INFO] Loading road network using osm backend implementation...
[INFO] Loading database from file: zlanelet2_maps_scripts/lanelet2_s_shape_superelevated_road.osm ...
[INFO] RoadNetwork loaded successfully.
[INFO] OBJ files location: /home/franco/maliput_ws_focal.
[INFO] Generating OBJ ...
[INFO] OBJ creation has finished.

real    0m38.100s
user    0m38.053s
sys 0m0.024s

The map is taking quite a lot and it isn't a large map at all.

Task

Investigate:

francocipollone commented 1 year ago

First, to fall I proceeded to evaluate the time that the different query times take using maliput_osm(which relies on maliput_sparse), using as a point of comparison maliput_malidrive, which is our most mature backend.

Raw time measuring

Time the commands take for each map [in seconds]:

In maliput_sparse, note that the higher the number of points describing the line strings, the higher the query time, therefore, the time for creating meshes will also be increased.

Analyzing the obj creation using a profiler

During the obj creation, several queries against the road geometry are performed, in order to properly analyze whether it is a lack of performance in the maliput::utility::GenerateObj algorithm or in maliput_sparse I decided to use a profiler in order to identify in which part of the code the time is spent the most.

For convenience, I decided to use Remotery, however I didn't use it directly, but via the interface that purposes ign-common3 which is more user friendly (profiler-tutorial)

Running profiler when creating obj file for:

Note: These images are zoomed in in a particular part for the purposes of this document.

Diving deeper into maliput_sparse, the queries are relying on a brute force algorithm every time that the line strings are analyzed, therefore the time of each particular query is higher when having linestrings defined with a higher number of points.

In particular for the obj creation, the road geometry is "sampled" using a small sample step and the Lane::lane_bounds and Lane::GetOrientation methods are called in each step. In consequence, the time for the obj creation increases considerably for the arc_lane_dense map.

Possible Solution

For increasing performance when dealing with line string geometry queries. We should reorganize the space of each line string into a kdtree or similar. Most of the queries rely on geometrical queries that return the closest point or the two closest points of the line string to an external xyz point. We could be largely benefited by using maliput::math::kdtree class and having one kdtree space for each line string defining the lane, in a way that the linestring-related queries are answered in a performing way.

francocipollone commented 1 year ago

CC: @agalbachicar

francocipollone commented 1 year ago

Some questions/assumptions to answer/comment

Performance analysis

I continued the analysis on the performance of this maliput_osm backend which mainly depends on it on maliput_sparse helper package.

For such a thing the following considerations were made:

Using maliput_multilane backend

For running the gazoo demo with only one MOBIL car:

delphyne_gazoo -m maliput_multilane -n 1

Note: By default, it would also spawn three railcar agents, which I disabled by code.

image

Some notes from the profiler:

Using maliput_osm backend

For running the gazoo demo with only one MOBIL car:

delphyne_gazoo -m maliput_osm -n 1

Note: By default, it would also spawn three railcar agents, which I disabled by code.

image

Here the results aren't that encouraging:

Conclusions

Proposals

francocipollone commented 1 year ago

Closed as completed