Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve performance of FastPolygonOperations constructor #33

Merged
merged 2 commits into from
Oct 22, 2018

Conversation

tyrasd
Copy link
Member

@tyrasd tyrasd commented Oct 10, 2018

Replaces the straight-forward O(n²) polygon slicing implementation with a quad-recursive O(n log(n)) algorithm (assuming that JTS' intersection method takes O(n) time to compute the intersection of a n-vertex polygon with another 4 vertex polygon). A minor additional change is that now, the number of bands is rounded up to the next power of two (mainly to make the implementation easier).

replaces old O(n²) polygon slicing implementation with a quad-recursive O(n log(n)) algorithm.
Geometry[] result = new Geometry[numBands*numBands];
traverseQuads(bandIterations, 0,0, env, geom, gf, result);

blocks = new ArrayList<>(Arrays.asList(result));
Copy link
Member Author

@tyrasd tyrasd Oct 10, 2018

Choose a reason for hiding this comment

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

actually, one could store the result directly as a Geometry[] variable in this.blocks (instead of the current ArrayList<Geometry> wrapper). But in order to stay binary compatible with current 0.5 code (that could be already running on an Ignite cluster for example 😉 ), it's probably better to keep it as it for now and change it in a later major version (0.6).

@tyrasd tyrasd added the performance Performance optimizations, bottlenecks of the current pipeline, etc. label Oct 10, 2018
@tyrasd
Copy link
Member Author

tyrasd commented Oct 10, 2018

Some quick & dirty benchmarks (timings are for a full oshdb-api request including oshdb processing time, ignite data serialization and other ohsome-api overhead):

region old implementation this pull request
~10k Points Polygon
(Thüringen boundary)
3.5 s 1.0 s
~60k Points MultiPolygon
(Germany boundary)
151 s 20 s

@tyrasd tyrasd requested a review from rtroilo October 10, 2018 15:56
Copy link
Member

@rtroilo rtroilo left a comment

Choose a reason for hiding this comment

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

.

@FabiKo117 FabiKo117 merged commit 1a60df5 into master Oct 22, 2018
@tyrasd tyrasd deleted the faster-polygon-operations branch October 22, 2018 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance optimizations, bottlenecks of the current pipeline, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants