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

[WIP] AVL tree + performance tweaking #42

Merged
merged 44 commits into from
Jan 1, 2018
Merged

[WIP] AVL tree + performance tweaking #42

merged 44 commits into from
Jan 1, 2018

Conversation

w8r
Copy link
Owner

@w8r w8r commented Sep 8, 2017

  • proceeding with work on adopting faster tree data structure
  • Took in @rowanwins changes for union construction
  • split the code for convenience
  • trying to tweak the performance

@rowanwins
Copy link
Collaborator

rowanwins commented Sep 13, 2017

Hi @w8r

I've been doing some scratching through this martinez implementation to see if it can provide anything useful

I wondered if this chunk in particular might help in the subdivide_segments function for unions given that we're experiencing slowness particuarly with our union operation...

My initial implementation of it is failing, I simply added the following but I think Im incorrectly interpreting the connector.add() as sortedEvents.push()

    if (operation === UNION && (event.point[0] > rightbound)) {
      while (eventQueue.length) {
        event = eventQueue.pop();
        if (!event.left) sortedEvents.push(event);
      }
      break;
    }

Will see if I come across anything else useful

@rowanwins
Copy link
Collaborator

Looking at this implementation it looks as though the creation of the polygon is done as new vertices are added, rather than at the end (which our connect_edges() currently appears to do...). Not sure if there are major gains here but it is quite different.

@rowanwins
Copy link
Collaborator

Also note there are some c++ files in here which you might find easier to read.

@rowanwins
Copy link
Collaborator

And another potential source for inspiration using php. This one looks relatively new and well organised.

@rowanwins
Copy link
Collaborator

Hi @w8r

Well I've made a very simple change but it looks like a made a big difference and martinez is now out-performing jsts for all operations. I think it could be taken a step further with the right knowledge of what's happening but it took me 1.5 hours just to add those 30 characters of code :)

@w8r
Copy link
Owner Author

w8r commented Sep 25, 2017

Oh this is amazing, you cut off so much unnecessary loops! I totally didn't see that opportunity

@rowanwins
Copy link
Collaborator

interestingly the benchmark test doesn't appear to make as much difference as the browser, I wonder why that is...

@rowanwins
Copy link
Collaborator

It looks like the next hurdle might be something in the subdivide_segments

@@ -4,7 +4,14 @@
// var abs = Math.abs;

module.exports = function equals(p1, p2) {
Copy link
Owner Author

Choose a reason for hiding this comment

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

But this one I have mostly kicked out trying to minimize function calls. However it didn't give much gain

Copy link
Contributor

Choose a reason for hiding this comment

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

Simple operations like this won't have much performance gains in the grand scheme of things.

However, dropping for loops helps a lot!

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah this was a bit of a long shot but I figured if it was a micro-optimisation that was being called a squillion times it might help, see https://jsperf.com/andcomparitor/1 (although the results are depenedent on what browser you use)

@w8r
Copy link
Owner Author

w8r commented Sep 25, 2017

Now I see some problem in difference on asia.geojson against a polygon with hole (it crashes), but I didn't check the output yet

@DenisCarriere
Copy link
Contributor

martinez is now out-performing jsts for all operations

👏 😄

@gap777
Copy link

gap777 commented Oct 19, 2017

@w8r we could really use these changes... any idea when you think they'll be ready to merge?

@rowanwins
Copy link
Collaborator

Hi @gap777

Unfortunantly it's still a little while away. Hopefully once I get the new Turf.js docs released in the next week I'll be able to do some digging into the remaining bugs.

@rowanwins
Copy link
Collaborator

Hi @w8r

I'm starting to look at this again, I'm determined to crack it one day!

You'll see I've added a new style of test which is designed to check each of the potential input geometries (polys, poly with hole, multipoly) against each of the operations. These test use super-simple geometries to try and debug and are clearly named so hopefully they will help us track down what is happening.

@w8r
Copy link
Owner Author

w8r commented Oct 23, 2017

This is amazing, feel free to poke me, I am supposed to have more free time this week

@rowanwins
Copy link
Collaborator

Will try and get the suite roughly ready and then will report back on those which are throwing issues.

@rowanwins
Copy link
Collaborator

Ah thanks for that. Looking at it the result of that holecut difference looks incorrect, while the visual result shown on the map looks ok the actual result array is incorrectly nested, I'll do a quick dig now and see if I can work out why...

@w8r
Copy link
Owner Author

w8r commented Dec 20, 2017

yes, nesting is the problem there

@rowanwins
Copy link
Collaborator

Think I've got it sussed, just running some more checks, stay tuned

@rowanwins
Copy link
Collaborator

Well that was good, I removed some lines that had always concerned me regarding the operation type. And I was also able to remove that final loop as well.

@rowanwins
Copy link
Collaborator

rowanwins commented Dec 20, 2017

Bah sorry confused myself when I was checking others. I know why it's not working, its because it's marked as an interior ring. But if it's an exterior ring on a difference operation, but the subject box is within the clipping bbox, then it should be treated as a hole. I haven't worked out how to best test for it though and rectify it.

@rowanwins
Copy link
Collaborator

Have pushed a fix for that difference hourglass nesting bug , not sure how solid it is but the tests pass.

@w8r
Copy link
Owner Author

w8r commented Dec 20, 2017

I guess everything is ok

@w8r
Copy link
Owner Author

w8r commented Dec 20, 2017

I'll squash if you don't mind, don't see how the separate commits would help reconstructing this drama

@w8r
Copy link
Owner Author

w8r commented Dec 20, 2017

#35 is still completely broken, but ok, it will be the next one https://codepen.io/w8r/pen/XVKNQw?editors=0010

@w8r
Copy link
Owner Author

w8r commented Dec 20, 2017

and #12 will be broken after the merge

@w8r
Copy link
Owner Author

w8r commented Dec 20, 2017

so it fixes #47,#45, #44, #43 (diff still broken), #17, #32

@gap777
Copy link

gap777 commented Dec 29, 2017

@w8r and @rowanwins - it sounded like you guys were headed towards a release soon. What's your intention in the near future?

@w8r w8r merged commit 8e89018 into master Jan 1, 2018
@w8r w8r deleted the rowanwins-avl-again branch January 1, 2018 20:08
@w8r
Copy link
Owner Author

w8r commented Jan 1, 2018

thank you @rowanwins !

@w8r
Copy link
Owner Author

w8r commented Jan 1, 2018

released as v0.3.0. I saw a couple of small problems with a tree and also how to improve the demo and releasing, that will go to the patches

@rowanwins
Copy link
Collaborator

That was epic @w8r !!!

@codeofsumit
Copy link

👏 👏 nice!

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

6 participants