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

Performance improvement #141

Merged
merged 26 commits into from
Dec 28, 2018
Merged

Conversation

doskabouter
Copy link
Contributor

First check envelope before calling CGAlgorithms::isPointInRing

@dbaston
Copy link
Member

dbaston commented Dec 10, 2018

Thanks for this, @doskabouter . I haven't merged it yet because I want to verify / quantify the performance impact myself. (I did test your earlier PR through PostGIS and saw quite a large performance gain, but Postgres adds a lot of noise to performance testing. I'd like to try it by calling GEOS directly from a simple C program.)

@doskabouter
Copy link
Contributor Author

And another 25% faster. Total improvement: twice as fast

@dbaston
Copy link
Member

dbaston commented Dec 27, 2018

I tested this without PostGIS in the loop and am seeing similar improvements. Intersects predicate goes from 24 to 11 seconds; intersection overlay goes from 48 to 20 seconds.

@@ -152,6 +152,8 @@ class GEOS_DLL PolygonBuilder {
std::vector<geomgraph::EdgeRing*> &newShellList,
std::vector<geomgraph::EdgeRing*> &freeHoleList);

using FastPIPRing = tuple<EdgeRing*, algorithm::locate::IndexedPointInAreaLocator*>;
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about defining an internal struct that holds this stuff? (I don't find get<0> terribly descriptive when I see it used.)

Also, any reason not to use std::unique_ptr<IndexedPointInAreaLocator> ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

internal struct sounds fine, I'll do that soon.
not using std::unique_ptr is due to my inexperience with c++. I assume that when used, the loop where those are delete'd can be removed?

Copy link
Member

Choose a reason for hiding this comment

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

I assume that when used, the loop where those are delete'd can be removed?

Yes, exactly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, it's quite a hassle (in fact I didn't succeed at it yet), to have a std::vector of structs containing a std::unique_ptr, I keep getting compiler errors about "attempting to reference a deleted function".
I could probably fix this by adding appropriate copy-constructor/move-constructor/destrutors but that seems (at least to me at the moment) like quite the overkill.

Copy link
Member

Choose a reason for hiding this comment

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

Are you working with Visual Studio by chance? If so, you may need to explicitly delete the copy constructor and assignment operator; see https://github.com/libgeos/geos/blob/master/include/geos/index/strtree/SIRtree.h#L83

If you can't make it work, just leave the raw pointer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed I'm using VS (2017). Must say those copy constructor issues are the least of the problems...
Main one being that VS doesn't resolve the namespaces correctly (I had to prepend a huge number of types with their namespace to get it to compile, and as such it's quite a hassle to create a proper pullrequesst,...)

@@ -336,7 +342,8 @@ PolygonBuilder::findEdgeRingContaining(EdgeRing *testEr,

for(auto const& tryShell: newShellList)
{
LinearRing *tryShellRing=tryShell->getLinearRing();
;
Copy link
Member

Choose a reason for hiding this comment

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

Remove extra semicolon

@@ -348,15 +355,15 @@ PolygonBuilder::findEdgeRingContaining(EdgeRing *testEr,
Coordinate testPt = operation::polygonize::EdgeRing::ptNotInList(testRing->getCoordinatesRO(), tsrcs);
bool isContained=false;

if(PointLocation::isInRing(testPt, tsrcs))
if (get<1>(tryShell)->locate(&testPt) != Location::EXTERIOR)
Copy link
Member

Choose a reason for hiding this comment

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

Fix indentation, use braces for if (style consistency with nearby code)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Braces were not present before, so I left it like that.
Will add them though

@doskabouter
Copy link
Contributor Author

Shall I continue adding improvements to this branch, (perhaps after this PR is merged?) or shall I create a new one for some other (f.e. missing envelope-checks) improvements?

@dbaston
Copy link
Member

dbaston commented Dec 28, 2018

I'd make a separate branch (and PR) for any improvements unrelated to this one.

@doskabouter
Copy link
Contributor Author

Ok, will do

@strk strk merged commit d75a294 into libgeos:master Dec 28, 2018
@doskabouter doskabouter deleted the st_intersection_improvement branch December 29, 2018 10:13
@doskabouter doskabouter restored the st_intersection_improvement branch December 29, 2018 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants