Repository navigation
Use JTS to determine applicable spatial rules - #1829
Conversation
|
Cool, thanks! Probably after this we should get rid of our own Polygon class and also use the JTS version elsewhere. |
|
|
Really nice, thanks for the great work. Did you have a chance to compare the performance of the JTS lookup vs. the array lookup? |
What is the limit for the test builds? |
|
We limit it explicitly to 100MB to detect memory issues very early: https://github.com/graphhopper/graphhopper/blob/master/pom.xml#L118. How much more would be required? |
|
@karussell i've lowered the number of points for the test from 5 to 1 million. |
Yes, that's somewhat expected. The lookup is currently optimized for look up performance. For me building the index was not that time critical. This is only done during the import, where time (adding a few seconds to minutes) plays only a minor role, but we might need to lookup > 200.000.000 edges for world wide imports. Also if we ever want to do the lookup during the route calculation. Thanks for providing some benchmark data and this nice PR 👍 |
The JTS approach should be fast enough to be used during the import. The benchmark is a bit pessimistic as i measured it with one rule for every country on the planet which results in an index with ~2.6k entries.
There is still room for improvement. The hit-rate of the spatial index seems to be a good candidate for optimization. Just take a look at the bounding box of Austria which covers half of Bavaria: Each point in the southern region of Bavaria needs to be tested against both polygons as the fast index/envelope shortcut doesn't work here. We could split bigger polygons in order to keep their Envelope small and therefor closer to the actual borders. |
|
Did a bit of profiling using VisualVM while recording roughly 2 minutes of execution time: Whole world index (2.6k polygons)Central europe index (54 polygons)Benchmark results
Seems like the size of the index isn't that crucial which means that we would need to lower the amount unnecessary PIP checks in order to speed things up. Note that the number of invocations of |
|
With the last change the lookup of 5 million points is down to 3.5s |
|
@karussell anything missing? |
|
We can close #1827 when we merge this branch. I just thought it would be better to break my changes into smaller units. |
|
Since we change the config value to: |
Thanks! Completely forgot to cherry-pick this commit: 9708e45 |
There was a problem hiding this comment.
Since this would work out of the box now and since we completely change the implementation, wouldn't it make sense to break the interface? Or maybe deprecate the lookupRule method and create a new lookupRules method. lookupRule could fall back to returning only the first result.
There was a problem hiding this comment.
The interfaces still need a bit of love but that will be the focus of the following PRs. The next step is going to be adding support for multiple overlapping rules with priorities.
#1808 describes the roadmap
There was a problem hiding this comment.
Overall this PR looks really good to me. It's great that we are now using JTS. I gave this PR a bit of live testing as well and it seems like everything is working fine. Also the import time for the area "Alps" seems to be more or less equally fast compared to master.
I added a few notes, but nothing critical. I think we can merge this PR.
|
@boldtrn i've addressed the issues you mentioned and rebased on the current master |
Thanks a lot. I added a lost minute note, sorry :). |
|
Thanks for the nice improvement @otbutz. I just merged this PR. |
|
On appveyor we get: SpatialRuleLookupBuilderTest.testSpeed:256 Benchmark must be finished in less than 10000ms Can we roughly half the complexity of that speed test to make it pass also on slightly weaker servers? |
I can also remove the assert and keep it only for debugging |
|
But then probably removing the entire test would make more sense. We could move it into the Measurement class instead? |
|
I wasn't aware of that class. Seems like a good fit. |
|
Excellent, thanks! I was wondering, @otbutz, how much performance do we gain by the tiling optimization in |
About 10-15% as far as i can remember but don't pin me down on this.
I tested a few optimizations to see if i can shove off a bit of execution time by using simpler checks to avoid the whole point-in-polygon logic wherever possible. Ideally you would want to find the biggest envelope which can fit entirely into the polygon without intersecting/covering any holes. As the country polygons are rather complex, finding this ideal inner envelope is quite hard(NP-complete?) and would require some kind of optimization algorithm. Breaking the polygon up into tiles is rather quick and servers as a good approximation. A small grid won't yield any benefits as most tiles will intersect with the border. If the grid is too big, the costs of the tile checks outweigh the regular point-in-polygon costs. I don't think that the tiling approach will cause problems for certain polygons. Either we have a high hitrate which allows us to dodge most of the pip logic or we don't have a lot/any tiles which eliminates the envelope checks. |




Builds on top of #1827 and uses JTS classes to handle border geometries and SpatialLookup.
This should also solve #1680 as JTS polygons are able to deal with holes.