-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Replace RTree with RBush #1641
Replace RTree with RBush #1641
Conversation
@@ -43,7 +43,7 @@ describe("iD.Tree", function() { | |||
var node = iD.Node({id: 'n', loc: [0.5, 0.5]}); | |||
base.rebase({ 'n': node }); | |||
tree.rebase(['n']); | |||
expect(tree.intersects(iD.geo.Extent([0, 0], [1, 1]), g)).to.eql([way, node]); | |||
expect(tree.intersects(iD.geo.Extent([0, 0], [1, 1]), g)).to.eql([node, way]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to change the order for the tests to pass, as RTree search doesn't guarantee any particular order of elements. Maybe it would be better to sort on both sides of assertion.
Added using bulk insertion for the graph. |
OK, tried to measure
|
@@ -1,41 +1,55 @@ | |||
iD.Tree = function(graph) { | |||
|
|||
var rtree = new RTree(), | |||
var rtree = rbush(), | |||
m = 1000 * 1000 * 100, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, what's the reason for multiplying/rounding of coordinates here? Tried removing this and it seems to make no difference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know. @ansis, can you explain?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... I can't remember. I'm not seeing a difference either. Its likely just a misconception that stuck around.
@mourner thanks for rbush btw. Its awesome to have a more readable and faster rtree.
I also noticed that diagonal lines are covered by one big rectangle, and that means that a lot of labels that could be drawn aren't because of false positives. In Kothic JS, we cover diagonal lines by a set of small offset rectangles, and I think you should try the same. Because of bulk insertion, it shouldn't affect performance much. |
Merged, thanks! I saw nice performance improvements too. |
Yay :) |
Replaces the old RTree with RBush, my new high-performance R-Tree implementation.
Everything seems to work smoothly and probably faster than before, but I don't know how to measure the exact performance impact — if you do, I'd be happy to hear the results.
One more thing worth exploring is bulk insertion for the labels code which is not used here because at the moment every insertion is dependent on results of previous ones (
tryInsert
function). If you can reorganize the code to batch unrelated insertions, we can use bulk insertion and increase performance.cc @jfirebaugh @tmcw