Skip to content

Commit

Permalink
Debug some backend timings
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed May 5, 2024
1 parent f72e71e commit c7f3be2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
11 changes: 11 additions & 0 deletions backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ utils = { git = "https://github.com/a-b-street/utils" }
wasm-bindgen = "0.2.87"
web-sys = { version = "0.3.64", features = ["console"] }
enum-map = "2.7.3"
web-time = "1.1.0"

# For local development, build dependencies in release mode once, but otherwise
# use dev profile and avoid wasm-opt.
Expand Down
10 changes: 10 additions & 0 deletions backend/src/isochrone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::time::Duration;

use anyhow::Result;
use geo::Coord;
use web_time::Instant;

use crate::costs::cost;
use crate::graph::{Graph, Mode, RoadID};
Expand All @@ -12,7 +13,9 @@ pub fn calculate(graph: &Graph, req: Coord, mode: Mode) -> Result<String> {
// 15 minutes
let limit = Duration::from_secs(15 * 60);

let t1 = Instant::now();
let cost_per_road = get_costs(graph, req, mode, limit);
let t2 = Instant::now();

// Show cost per road
let mut features = Vec::new();
Expand All @@ -29,6 +32,13 @@ pub fn calculate(graph: &Graph, req: Coord, mode: Mode) -> Result<String> {
}
let gj = geojson::GeoJson::from(features);
let x = serde_json::to_string(&gj)?;
let t3 = Instant::now();

info!("Total backend isochrone time: {:?}", t3 - t1);
for (label, dt) in [("get_costs", t2 - t1), ("to GJ", t3 - t2)] {
info!(" {label} took {dt:?}");
}

Ok(x)
}

Expand Down
22 changes: 22 additions & 0 deletions backend/src/scrape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use osm_reader::{Element, OsmID};
use rstar::primitives::GeomWithData;
use rstar::RTree;
use utils::Tags;
use web_time::Instant;

use crate::amenity::Amenity;
use crate::graph::{
Expand All @@ -17,6 +18,7 @@ use crate::graph::{
use crate::route::Router;

pub fn scrape_osm(input_bytes: &[u8]) -> Result<Graph> {
let t1 = Instant::now();
info!("Parsing {} bytes of OSM data", input_bytes.len());
// This doesn't use osm2graph's helper, because it needs to scrape more things from OSM
let mut node_mapping = HashMap::new();
Expand Down Expand Up @@ -70,6 +72,7 @@ pub fn scrape_osm(input_bytes: &[u8]) -> Result<Graph> {
Element::Bounds { .. } => {}
})?;

let t2 = Instant::now();
info!("Splitting {} ways into edges", highways.len());
let graph = utils::osm2graph::Graph::from_scraped_osm(node_mapping, highways);

Expand Down Expand Up @@ -112,8 +115,10 @@ pub fn scrape_osm(input_bytes: &[u8]) -> Result<Graph> {
a.point = graph.mercator.pt_to_mercator(a.point.into()).into();
}

let t3 = Instant::now();
snap_amenities(&mut roads, &amenities);

let t4 = Instant::now();
let closest_intersection = EnumMap::from_fn(|mode| {
let mut points = Vec::new();
for i in &intersections {
Expand All @@ -128,6 +133,17 @@ pub fn scrape_osm(input_bytes: &[u8]) -> Result<Graph> {
});

let router = EnumMap::from_fn(|mode| Router::new(&roads, mode));
let t5 = Instant::now();

info!("Total backend setup time: {:?}", t5 - t1);
for (label, dt) in [
("parsing", t2 - t1),
("making graph", t3 - t2),
("amenities", t4 - t3),
("router", t5 - t4),
] {
info!(" {label} took {dt:?}");
}

Ok(Graph {
roads,
Expand Down Expand Up @@ -169,6 +185,12 @@ fn calculate_access(tags: &Tags) -> EnumMap<Mode, Direction> {
}
}
}

if let Some(conditional_speed) = lane_direction.maxspeed.get(muv_mode) {
if let Some(_speed) = conditional_speed.base() {
// TODO
}
}
}
}
}
Expand Down

0 comments on commit c7f3be2

Please sign in to comment.