speed of insert
cirlam opened this issue · comments
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?
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);
That is indeed much quicker! Thank you for the help.