Skip to content

Use entire road geometry for NameSimilarityEdgeFilter - #2320

Merged
easbar merged 4 commits into
masterfrom
name_filter_geometry
May 16, 2021
Merged

easbar merged 4 commits into
masterfrom
name_filter_geometry

Conversation

@easbar

@easbar easbar commented May 14, 2021

Copy link
Copy Markdown
Member

Fixes #2319

@easbar
easbar requested a review from karussell May 14, 2021 09:02
private static BBox createBBox(NodeAccess na, EdgeIteratorState edgeState) {
return BBox.fromPoints(na.getLat(edgeState.getBaseNode()), na.getLon(edgeState.getBaseNode()),
na.getLat(edgeState.getAdjNode()), na.getLon(edgeState.getAdjNode()));
private static BBox createBBox(EdgeIteratorState edgeState) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This method was no longer used since #1950, but it did the same wrong thing (exclude pillar nodes)

Comment on lines +176 to +183
PointList geometry = edgeState.fetchWayGeometry(FetchMode.ALL);
BBox bbox = new BBox(180, -180, 90, -90);
for (int i = 0; i < geometry.getSize(); i++) {
bbox.minLon = Math.min(bbox.minLon, geometry.getLon(i));
bbox.maxLon = Math.max(bbox.maxLon, geometry.getLon(i));
bbox.minLat = Math.min(bbox.minLat, geometry.getLat(i));
bbox.maxLat = Math.max(bbox.maxLat, geometry.getLat(i));
}

@easbar easbar May 14, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Finding the bounds of a point list is maybe something we do elsewhere already and we could create a helper method for this otherwise. Unfortunately I could not find something like it. -> Ah we have BBox#update, I updated this.

Btw. why has PointList getSize() and size()? And looking at point list I was not even sure if size() really returns the number of elements or rather the capacity?! (should be ok)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Maybe we should store the bounds of each edge including the geometry for such use cases. There are two very similar todos here:

// 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);

BBox bbox = GHUtility.createBBox(edge);
if (p.getBounds().intersects(bbox))
return p.intersects(edge.fetchWayGeometry(FetchMode.ALL).makeImmutable()); // TODO PERF: cache bbox and edge wayGeometry for multiple area

na.getLat(edgeState.getAdjNode()), na.getLon(edgeState.getAdjNode()));
private static BBox createBBox(EdgeIteratorState edgeState) {
// we should include the entire geometry, see #2319
PointList geometry = edgeState.fetchWayGeometry(FetchMode.ALL);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've seen this usage pattern a few times now. We create a PointList only to do some logic with each point and throw it away later. Wouldn't it be better to be able to consume them on-the-fly with a visitor pattern?

e.g edgeState.visitWayGeometry(FetchMode.ALL, visitor);

@easbar easbar May 14, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, maybe. But for this case I wonder if we should simply store the bounding box for each edge. It looks like this would improve the code in GraphEdgeIdFinder and CustomWeightingHelper as well?! (but obviously we'd have to measure the difference to actually know if it makes a difference).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder if we should simply store the bounding box for each edge.

My europe import logs roughly 92 million edges. That's about 2.8GB of bbox information if we stored minlon,minlat,maxlon,maxlat per edge?

@easbar easbar May 14, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, if we used four doubles (4*8=32bytes). But that would be very wasteful. We can definitely reduce precision there (4*4bytes is more than enough), and maybe we can even just store the indices of the point list. Then maybe 4bytes per edge is enough (assuming no geometry has more than 256 points, but not sure if this is true).

@easbar easbar May 14, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

... and we could probably even somehow restrict this to 'curved' edges only, because for straight edges using the tower node coordinates as bounding box is often sufficient. For example we could store a allPillarNodesWithinTowerNodesBBox bit and only when it is false we would access the additional bbox data. Otherwise we would calculate the bbox from the tower node coordinates. I think there would be very many edges with allPillarNodesWithinTowerNodesBBox=true.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Implemented visitor access: #2321

@easbar

easbar commented May 16, 2021

Copy link
Copy Markdown
Member Author

I had to fix the routing measurement for point_hint, because so far we always set the point_hint to the name of the very first edge. But to test the speed of the look-ups with point hints I think we should rather use some point hint that cannot be found (worst case scenario in terms of performance). I fixed this here: b8a25d7 and it changed the measured routing CH speed with point hints from about 1.5ms to 1.8ms, so we can probably say that point_hints make route calculation (including location lookup, but no instructions, serialization etc.) about 20% slower.

After fixing this I compared the performance (metrics.routingCH_with_hints.mean) of this PR vs. master:

map master this branch
germany 1.78ms 1.83ms
bayern 1.19ms 1.21ms

The difference is less than 3% even on the smaller map where I assume the relative amount of time spent to lookup the locations is larger (because the routes are shorter). I think we can conclude that the bbox/geometry check does not play an important role and not too surprisingly the majority of the additional time we need to use point_hint is spent on the string comparison checks.

Btw I also did a quick performance comparison for the current scenario where we only use the tower nodes. Not using a PointList via fetchWayGeometry and instead accessing the tower node coordinates directly like nodeAccess.getLat(iter.getBaseNode()) did not make a significant difference here either, <2%.

@easbar
easbar merged commit 4fe4f9a into master May 16, 2021
@easbar
easbar deleted the name_filter_geometry branch May 16, 2021 12:57
@karussell karussell added the bug label May 17, 2021
@karussell karussell added this to the 3.0 milestone May 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Point hint is not working as expected for curved roads

3 participants