-
Notifications
You must be signed in to change notification settings - Fork 233
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
Experimental "all" codepath #11
Conversation
That's an interesting suggestion to try, thanks Tom! I'll run the perf tests (I did them mostly with node, Tests also leave a lot to be desired, I'll try to improve the coverage significantly as one of the next step improvements. |
@@ -38,7 +42,11 @@ rbush.prototype = { | |||
childBBox = node.leaf ? this._toBBox(child) : child.bbox; | |||
|
|||
if (this._intersects(bbox, childBBox)) { | |||
(node.leaf ? result : nodesToSearch).push(child); | |||
if (this._contains(bbox, childBBox)) { | |||
this._all(node, result); |
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.
Here's the culprit! The loop goes through node children, but if the child bbox fits into the search area, you're then running _all
on the whole node instead of just the child that fits.
Rewriting this line like this fixes the issue and provides ~3x improvement of 10% searches in my tests:
if (node.leaf) {
result.push(child);
} else {
this._all(child, result);
}
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 wonder why the tests pass with this. :) There should a mistake there as well.
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.
Well found @mourner! I've updated the branch to include your fix.
@twpayne Thanks Tom! Any idea why the test passed before the fix? |
I don't know. It may be that it's just a property of the test data that we're using that means that the bug did not manifest in this case. For testing these sort of data structures, I often generate random data and test my code against a known good (but maybe slow, or trivial) implementation, and check that both return the same result. |
Thanks for the second fix :) |
@twpayne it would be great to find a test case that fails without the fix but passes in both the latest master and the version before the pull, so we could avoid potential regressions when improving something in future. |
OK, will do. It'll take me a few days (very busy at the moment) but I promise to do it! |
No rush Tom, thanks again! This is a really awesome improvement — dramatically better times on all searches (updating benchmark results now). |
This PR adds a short code path when it's known that all children of a node overlap the target bounding box.
Right now, this code is neither tested nor properly benchmarked. (How do I run the tests?).
Observations:
Array.prototype.push.apply
) to collapse common cases.debug/perf.js
tests) then the advantage will be smaller.At this stage: comments welcome! Maybe this helps, maybe it doesn't....