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

Replaced spade with rstar #314

Merged
merged 1 commit into from
Dec 2, 2018
Merged

Replaced spade with rstar #314

merged 1 commit into from
Dec 2, 2018

Conversation

Stoeoef
Copy link
Contributor

@Stoeoef Stoeoef commented Nov 22, 2018

Hi there!

I'm in the process of extracting spade's rtree and was finally able to get the geo tests running with the planned replacement crate: rstar.
Since the results so far look really promising, I'd like to share them with this PR to get some first reactions.
The goodies:

  • Reduced compilation times for geo workspace: cargo clean && cargo build was reduced to 11s (from 40s) on my local machine
  • Benchmark improvements:

simplify vwp f32 time: [17.300 ms 17.413 ms 17.551 ms]
change: [-70.837% -70.698% -70.558%] (p = 0.00 < 0.05)
Performance has improved.

The smaller build times may actually justify to use rstar without a feature flag.

Some TODO's before I'm willing to remove the WIP status:

  • I'll perform a review of the changes myself again
  • The simplify vwp algorithm was adapted a bit, I'll need to investigate if it is still correct. I'll add a comment to the appropriate section and ask for a special review.
  • I need to check the test coverage of rstar for the methods used by geo, Should not be too dramatic, but I want those tests anyway...

Also, rstars public interface is likely to change in the near future - however, I would keep geo updated should any breaking change make this necessary. That is, after all, in my own interest, as failing geo test cases will likely mean that something is wrong with my changes.

Any thoughts or opinions are welcome. Please keep in mind that, as I just published the rstar crate, it will take a while until it is in a polished state. I hope does not pose too much of a problem.

@urschrei
Copy link
Member

Oh, amazing. Thank you! Feel free to ping me about the vwp changes – if the tests are still passing, I'm pretty confident that it'll be OK, but I can certainly cook up some more to exercise it even more thoroughly.

@frewsxcv
Copy link
Member

Wow, this looks awesome! Extracting out the r*-tree was a great idea 👍

I just skimmed through the code and everything is look good, ping me or @urschrei if you need any help! 👋

@frewsxcv frewsxcv mentioned this pull request Nov 23, 2018
@Stoeoef Stoeoef changed the title WIP: Replaced spade with rstar Replaced spade with rstar Nov 29, 2018
Copy link
Contributor Author

@Stoeoef Stoeoef left a comment

Choose a reason for hiding this comment

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

I've removed the WIP status as I am happy with the changes. Feel free to modify the Cargo.toml versions, changing them to something final will require a cargo publish I believe. Also, if there are any other contribution rules (like running cargo fmt), now would be a good time to mention.

failure = "0.1.2"
postgis = { version = "0.6", optional = true }
proj = { version = "0.5", optional = true }
geo-types = { version = "0.2", features = ["spade"] }
geo-types = { path = "../geo-types", features = ["rstar"] }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will need to be updated in order to publish the crate... feel free to change it to any version you see fit.

Copy link
Member

Choose a reason for hiding this comment

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

yep, this makes sense 👍

let line_1 = Line::new(left_point, middle_point);
let line_2 = Line::new(middle_point, right_point);
assert!(tree.remove(&line_1).is_some());
assert!(tree.remove(&line_2).is_some());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that I originally had a different assertion:
assert!(tree.remove(&line_1).is_some() || tree.remove(&line1.reverse().is_some())
as I was not sure in which direction a line would have been loaded.

I then realized that, as long as all lines are going "in the same direction", these assumptions should hold: If edges A->B and B->C exist, then they should be loaded as (A,B), (B,C) in contrast to (A,B),(C,B)).

Since all incoming lines are either the lines of a line string (which is directed) or the inner rings of a polygon (which are also directed), these assertions should hold. However, you may want to check this yourselves. Please note that the spade algorithm was not susceptible to this, that's why I'm so cautious. It was though, at the same time, much more inefficient.

Copy link
Member

Choose a reason for hiding this comment

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

As you say, this could only be a problem for us if someone constructs an invalid geometry. @frewsxcv, I know we aren't currently checking for that, but I don't know if this is the right place to enforce it – I think it's reasonable for individual algorithms to assume that incoming geometries are valid.

Copy link
Member

Choose a reason for hiding this comment

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

agreed. we still need to work on our validation story in this crate, but for the time being, i think it's okay to assume geometry coming in is invalid so this looks good 👍

Copy link
Member

@frewsxcv frewsxcv left a comment

Choose a reason for hiding this comment

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

amazing work @shterrett, thanks for making this improvement and contribution! ✨

as this is a breaking change for both 'geo' and 'geo-types', i'm not yet going to publish a new version – i'm thinking about including other breaking changes in the next release and would prefer to group them up in one release

let line_1 = Line::new(left_point, middle_point);
let line_2 = Line::new(middle_point, right_point);
assert!(tree.remove(&line_1).is_some());
assert!(tree.remove(&line_2).is_some());
Copy link
Member

Choose a reason for hiding this comment

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

agreed. we still need to work on our validation story in this crate, but for the time being, i think it's okay to assume geometry coming in is invalid so this looks good 👍

@frewsxcv
Copy link
Member

frewsxcv commented Dec 2, 2018

bors r+

bors bot added a commit that referenced this pull request Dec 2, 2018
314: Replaced spade with rstar r=frewsxcv a=Stoeoef

Hi there!

I'm in the process of extracting spade's rtree and was finally able to get the geo tests running with the planned replacement crate: `rstar`.
Since the results so far look really promising, I'd like to share them with this PR to get some first reactions.
The goodies:
- Reduced compilation times for `geo` workspace: `cargo clean && cargo build` was reduced to 11s (from 40s) on my local machine
- Benchmark improvements:

> simplify vwp f32        time:   [17.300 ms 17.413 ms 17.551 ms]                          
>                        change: [-70.837% **-70.698%** -70.558%] (p = 0.00 < 0.05)
>                        Performance has improved.

The smaller build times may actually justify to use `rstar` without a feature flag.

Some TODO's before I'm willing to remove the WIP status:
- [x] I'll perform a review of the changes myself again
- [x] The simplify vwp algorithm was adapted a bit, I'll need to investigate if it is still correct. I'll add a comment to the appropriate section and ask for a special review.
- [x] I need to check the test coverage of `rstar` for the methods used by `geo`, Should not be too dramatic, but I want those tests anyway...

Also, `rstars` public interface is likely to change in the near future - however, I would keep `geo` updated should any breaking change make this necessary. That is, after all, in my own interest, as failing geo test cases will likely mean that something is wrong with my changes.

Any thoughts or opinions are welcome. Please keep in mind that, as I just published the `rstar` crate, it will take a while until it is in a polished state. I hope does not pose too much of a problem.


Co-authored-by: Stefan Altmayer <stoeoef@gmail.com>
@bors
Copy link
Contributor

bors bot commented Dec 2, 2018

Build succeeded

@bors bors bot merged commit 7d1ddc6 into georust:master Dec 2, 2018
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

3 participants