Repository navigation
perf(drivingDistance): compute get_depth in O(V) - #9
Merged
Merged
Conversation
Assisted-by: Claude Opus 5.5 (1M context)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Since 3.6.0,
pgr_drivingDistance(andpgr_withPointsDD) compute thedepthcolumn withdetail::get_depth, which scans all vertices once per reached vertex: O(reached × V).On a nationwide road network (3,881,601 edges, 3,711,035 vertices), a 30-minute catchment (123,945 reached nodes) takes 161 s on develop vs 2.8 s on 3.5.1.
This PR rewrites
get_depthto run in O(V): build the children lists of the predecessor tree in one pass (CSR layout), then walk it breadth first from the root.remove_detailsis still applied first whendetails => false(callers reuse the modified predecessors)std::map<int64_t, int64_t>) and callers are unchangedBenchmark
Release build, PostgreSQL 17, Apple M1 Pro, median of 3 runs.
SELECT count(*) FROM pgr_drivingDistance('SELECT id, source, target, cost, reverse_cost FROM roads_jp', 2077846, <limit>)The remaining ~2.4 s is reading the edges and building the graph.
Verification
pgr_drivingDistanceandpgr_withPointsDD; one/many roots, directed/undirected, equicost, details true/false): 8,934 rows,diffemptydijkstra/driving_distance,withPoints/withPointsDD,spanningTreepass (Debug build)driving_distanceunchangedpgtap/dijkstra/driving_distance/edge_cases/depth.pg(13 tests): there was no direct test of thedepthcolumn ofpgr_drivingDistancedepth = depth(pred) + 1on several signatures, a 2000-vertex chain,pgr_withPointsDDwithdetails => falseremove_detailscall makes test 9 failNot in this PR (existing issues found while testing)
drivingDistance_with_equicostdoescontinuewithout++i, so only the root rows are returned (e.g.ARRAY[11, 16, 99999]), and the missing root gets depth -1 (0 without equicost)pgr_withPointsDD(..., equicost => true, details => false)returns a point (negative node) in the resultdriving_distance_withPoints_driver.cppusesd.at(row.node)withoutbreak, unliketo_postgres.cpp(find+break)