From c7f3be25f6b76d4c275738573eed02382d186554 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Sun, 5 May 2024 13:52:47 +0100 Subject: [PATCH] Debug some backend timings --- backend/Cargo.lock | 11 +++++++++++ backend/Cargo.toml | 1 + backend/src/isochrone.rs | 10 ++++++++++ backend/src/scrape.rs | 22 ++++++++++++++++++++++ 4 files changed, 44 insertions(+) diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 3b885e1..3d07261 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -92,6 +92,7 @@ dependencies = [ "utils", "wasm-bindgen", "web-sys", + "web-time", ] [[package]] @@ -1103,6 +1104,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "which" version = "4.4.2" diff --git a/backend/Cargo.toml b/backend/Cargo.toml index dbe6ddb..2443b34 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -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. diff --git a/backend/src/isochrone.rs b/backend/src/isochrone.rs index 6cc7c2a..22a78d3 100644 --- a/backend/src/isochrone.rs +++ b/backend/src/isochrone.rs @@ -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}; @@ -12,7 +13,9 @@ pub fn calculate(graph: &Graph, req: Coord, mode: Mode) -> Result { // 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(); @@ -29,6 +32,13 @@ pub fn calculate(graph: &Graph, req: Coord, mode: Mode) -> Result { } 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) } diff --git a/backend/src/scrape.rs b/backend/src/scrape.rs index b7bc7df..4f945c5 100644 --- a/backend/src/scrape.rs +++ b/backend/src/scrape.rs @@ -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::{ @@ -17,6 +18,7 @@ use crate::graph::{ use crate::route::Router; pub fn scrape_osm(input_bytes: &[u8]) -> Result { + 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(); @@ -70,6 +72,7 @@ pub fn scrape_osm(input_bytes: &[u8]) -> Result { Element::Bounds { .. } => {} })?; + let t2 = Instant::now(); info!("Splitting {} ways into edges", highways.len()); let graph = utils::osm2graph::Graph::from_scraped_osm(node_mapping, highways); @@ -112,8 +115,10 @@ pub fn scrape_osm(input_bytes: &[u8]) -> Result { 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 { @@ -128,6 +133,17 @@ pub fn scrape_osm(input_bytes: &[u8]) -> Result { }); 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, @@ -169,6 +185,12 @@ fn calculate_access(tags: &Tags) -> EnumMap { } } } + + if let Some(conditional_speed) = lane_direction.maxspeed.get(muv_mode) { + if let Some(_speed) = conditional_speed.base() { + // TODO + } + } } } }