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

speed of insert #87

Closed
cirlam opened this issue Nov 22, 2018 · 2 comments
Closed

speed of insert #87

cirlam opened this issue Nov 22, 2018 · 2 comments

Comments

@cirlam
Copy link

cirlam commented Nov 22, 2018

Hi,

I've seen the performance benchmarks on the readme page, which look impressive.
However, when adding cities from "all-the-cities" (as in your geokdbush and geoflatbush test scripts), I am seeing quite slow performance.

I have created a very simple project to test this by creating an empty node.js project with the following code in index.js and running it.

const rbush = require('rbush');
var cities = require('all-the-cities');

console.log("creating new r tree")

tree = rbush(16, ['[0]', '[1]', '[0]', '[1]']);

for(i=0; i<cities.length; i++) {
    console.log("i: "+i);
    var city = cities[i];
    tree.insert(city.lon, city.lat);
}

initially it rattles through the first 300-400 very quickly, but then seems to exponentially slow down with the more data it loads. After ~1000 points it takes roughly 1 second for every insert.

Is this behaviour expected?

@mourner
Copy link
Owner

mourner commented Nov 22, 2018

You're misusing the API. Either use the default format and do:

tree.insert({minX: city.lon, minY: city.lat, maxX: city.lon, maxY: city.lat});

Or use the ['.lon', '.lat', '.lon', '.lat'] format and then do:

tree.insert(city);

@mourner mourner closed this as completed Nov 22, 2018
@cirlam
Copy link
Author

cirlam commented Nov 22, 2018

That is indeed much quicker! Thank you for the help.

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

No branches or pull requests

2 participants