geofirex icon indicating copy to clipboard operation
geofirex copied to clipboard

Performance takes a major hit (presumably when you hit a geohash border)

Open burggraf opened this issue 5 years ago • 2 comments

I've been troubleshooting a nasty performance issue that seemed to occur randomly. That is, until I narrowed it down. Take the following example:

Searching for properties near Fontana, California. If I search within a 4km radius, I get 408 results in about 2 seconds. If I search within a 5km radius, I get 555 results in about 40 seconds.

Somewhere between 4km and 5km I'm hitting an invisible wall which makes the query 20x slower.

Here's the relevant code (I had profiling code in there to show the exact performance but I removed it for simplicity:

this.propertiesCollection = this.geo.collection('properties', ref =>
    ref.where('subtype', '==', 'Residential')
);
const center = this.geo.point(34.1087656, -117.5328097); // Fontana, California
const radius = 4;
this.propertiesCollection.within(center, radius, 'position').subscribe((results) => {
    this.properties = results;
});

burggraf avatar Apr 18 '19 18:04 burggraf

If this is helpful:

  1. a radius of 4.89km takes 2 seconds to complete (as well as any radius below 4.98)
  2. a radius of 4.90km takes 40 seconds to complete (as well as any radius above 4.90)

burggraf avatar Apr 18 '19 20:04 burggraf

4.89km appears to be the changeover point from a 5 character to a 4 character geohash. See https://github.com/codediodeio/geofirex/blob/25a06a9988fc7ea2d28e6c46f4703c53f5e7d80e/src/util.ts#L19

philipallfrey avatar Jul 29 '19 23:07 philipallfrey