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

Refactor map_model to store Lanes inside of their parent Roads #747

Merged
merged 7 commits into from
Sep 6, 2021

Conversation

dabreegster
Copy link
Collaborator

During #597, we changed from a simple flat Vec<Lane> to a BTreeMap<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 of BTreeMap 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 parent Intersection 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 a BTreeMap query. This change also greatly simplifies a bunch of APIs -- we don't need to pass the whole Map to compute some stuff about roads, we no longer have this odd duplicate lanes_ltr: Vec<(LaneID, Direction, LaneType)> listing in each Road.

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 slow make_input_graph problem.

Some ideas for future cleanups:

  • Make DrawMap store the DrawLanes nested under DrawRoad, same as the map model. Right now we use a HashMap<LaneID, DrawLane>, which performs fine.
  • If we wanted to try squeezing down file size at the expense of complexity or slower startup time, we could stop serializing 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.

@dabreegster dabreegster merged commit 6dcf417 into master Sep 6, 2021
@dabreegster dabreegster deleted the road_embed_lanes branch September 6, 2021 02:53
dabreegster added a commit that referenced this pull request Oct 8, 2021
by squeezing some start-up performance of huge maps. #746

Shaving at least 1 second off quadtree initialization in huge_seattle
from this, no noticeable effects otherwise.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant