Refactor map_model to store Lanes inside of their parent Roads #747
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
During #597, we changed from a simple flat
Vec<Lane>
to aBTreeMap<LaneID, Lane>
, because while editing roads, we might delete or create new lanes. The ID space became non-contiguous. Since then, I've seen some slight perf degradation and lots ofBTreeMap
lookups during profiling. #746 and working on adding new routing parameters motivated me to look at this.The idea is similar to how we made
Turns
live inside of their parentIntersection
in #675.LaneID
now encodes the parent road and the offset from the left side of the road, so looking up a lane becomes two array lookups, not aBTreeMap
query. This change also greatly simplifies a bunch of APIs -- we don't need to pass the wholeMap
to compute some stuff about roads, we no longer have this odd duplicatelanes_ltr: Vec<(LaneID, Direction, LaneType)>
listing in eachRoad
.I'm having trouble with my profiler still, but I benchmarked
make_input_graph
for bike pathfinding. Before this PR, I get around 1.1s, and after, I get around 0.97s. Very slight, but noticeable, improvement. Also a very slight file size savings, since we store less redundant data --huge_seattle
drops about 5MB, from 268MB. Definitely more profiling and optimization is needed to address the slowmake_input_graph
problem.Some ideas for future cleanups:
DrawMap
store theDrawLanes
nested underDrawRoad
, same as the map model. Right now we use aHashMap<LaneID, DrawLane>
, which performs fine.lane_center_pts
and lazily calculate it from the road when needed. Probably not worth it; large map files are just a proxy for the real goal of fast startup time on large maps in the web.I'm regenerating everything now, will merge once that's successful.