Closed jaredlockhart closed 8 years ago
@hannosch r?
@jaredkerim My comments are in #285 - code speaks more clearly :)
And yeah, the DB would have the additional R-Tree index, which is missing in the in-memory case. But it does add the extra network latency to talk to the DB each time. If the two are close in runtime, doing it locally is definitely better.
Rather than compare distances to every country, attempt to find a country which contains the point and fail fast. Otherwise compute distances and find the nearest one.
I compared performance between doing this in memory and letting the database do it using st_contains, and the performance with the db was every so slightly worse than the in memory case, but only slightly. However, reducing load on the db is a good thing, so I think doing it in memory should be fine. This is roughly 4 times faster than simply sorting by all distances and doing no containment checks, according to my local benchmarking.