mozilla-services / location-leaderboard

A leaderboard service for Mozilla Geolocation Stumbling
Mozilla Public License 2.0
4 stars 5 forks source link

Improve performance of compute_ranks country matching #282 #283

Closed jaredlockhart closed 8 years ago

jaredlockhart commented 8 years ago

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.

jaredlockhart commented 8 years ago

@hannosch r?

coveralls commented 8 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling e6a52b261e5090a8210e0514c72ba04f2a0dde96 on 282 into 5fa2be8cf7a513d155bc30402df8e34a61bfecb8 on master.

hannosch commented 8 years ago

@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.