Skip to content

Skip shapes which don't block any edges - #2305

Merged
karussell merged 1 commit into
graphhopper:masterfrom
otbutz:improve_blocking
May 7, 2021
Merged

karussell merged 1 commit into
graphhopper:masterfrom
otbutz:improve_blocking

Conversation

@otbutz

@otbutz otbutz commented May 6, 2021

Copy link
Copy Markdown
Contributor

BlockArea currently treats an empty GHIntHashSet the same way as a non-existing cache for blocked edges. But a small shape which doesn't cover edges in the graph would also yield an empty GHIntHashSet. For those cases BlockArea would resort to the more expensive bbox/shape intersection logic:

public final boolean intersects(EdgeIteratorState edgeState) {
PointList pointList = null;
BBox bbox = null;
for (int shapeIdx = 0; shapeIdx < blockedShapes.size(); shapeIdx++) {
GHIntHashSet blockedEdges = edgesList.get(shapeIdx);
// blockedEdges acts as cache that is only useful when filled and for non-virtual edges
if (!blockedEdges.isEmpty() && edgeState.getEdge() < baseEdgeCount) {
if (blockedEdges.contains(edgeState.getEdge()))
return true;
continue;
}
// compromise: avoid expensive fetch of pillar nodes, which isn't yet fast for being used in Weighting.calc
if (bbox == null)
bbox = GHUtility.createBBox(edgeState);
Shape shape = blockedShapes.get(shapeIdx);
if (shape.getBounds().intersects(bbox)) {
if (pointList == null)
pointList = edgeState.fetchWayGeometry(FetchMode.ALL).makeImmutable();
if (shape.intersects(pointList))
return true;
}
}
return false;
}

I changed the logic to explicitly store null as the cache for blocked edges if the shape is to large so we can properly determine if we have no cache or if it's just empty.

@karussell

Copy link
Copy Markdown
Member

If a shape does not cover edges - maybe we should even throw an exception? (it might be too ugly?)

Did you had a chance to measure the query difference? Because this API is kind of legacy and if the difference is huge it will be critical to implement this for the new option via custom model too.

@otbutz

otbutz commented May 6, 2021

Copy link
Copy Markdown
Contributor Author

Screenshot_20210506_111718

@otbutz

otbutz commented May 6, 2021

Copy link
Copy Markdown
Contributor Author

Noticed this while benchmarking requests with a few blocked points. And e.g a point might not always cover an edge in the graph if the road is not present in OSM.

@otbutz

otbutz commented May 6, 2021

Copy link
Copy Markdown
Contributor Author

We could also drop these kind of shapes. There's no point to do the checks if we know that we won't find any intersections?

@karussell

Copy link
Copy Markdown
Member

Yes, either this or throwing an exception.

@otbutz

otbutz commented May 6, 2021

Copy link
Copy Markdown
Contributor Author

Apart from GraphHopperTest:556 everything seems to work.

@otbutz
otbutz force-pushed the improve_blocking branch from a90a421 to efb73e6 Compare May 6, 2021 11:34
@otbutz

otbutz commented May 6, 2021

Copy link
Copy Markdown
Contributor Author

Shouldn't have skipped my ☕ Readded the continue statement in the intersect check loop and everything is working as expected

@otbutz
otbutz marked this pull request as ready for review May 6, 2021 11:48
@otbutz otbutz changed the title Differentiate between empty and non existing edge cache Skip shapes which don't block any edges May 6, 2021
@otbutz
otbutz force-pushed the improve_blocking branch from f8e325f to 7872c27 Compare May 7, 2021 08:35
@otbutz
otbutz requested a review from karussell May 7, 2021 08:36

@karussell karussell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you - LGTM!

@karussell
karussell merged commit e806a5c into graphhopper:master May 7, 2021
@karussell karussell added this to the 3.0 milestone May 7, 2021
@otbutz

otbutz commented May 11, 2021 •

Copy link
Copy Markdown
Contributor Author

@karussell the id lookup currently only works for non-virtual edges. Could we use the same mechanism as in EdgeIdDetails ?

int edge;
if (edgeState instanceof VirtualEdgeIteratorState)
   edge = GHUtility.getEdgeFromEdgeKey(((VirtualEdgeIteratorState) edgeState).originalEdgeKey());
else
   edge = edgeState.getEdge();

I'm working on a solution for #2313 and i'd like to avoid passing around a Graph instance just to obtain the limit of the non-virtual edges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants