SERIOUSLY LORD FETCH - SORT IT OUT!
71 watchers
Oct 2012
2:47pm, 23 Oct 2012
4,160 posts
|
sprouty76
Oh yeah, it'll work, but will probably be less efficient. For example, think about the case where somebody does 5 laps of a park. In the old scheme each subsequent lap doesn't increase the area under consideration, because the area covered by the min & max of lat & long will remain the same (assuming no deviation from the previous lap) In the new scheme, you'll be going along the route, breaking it into lengths of (say) 1 mile and building each rectangle. Unless the route is an exact multiple of 1 mile, each lap will produce rectangles overlapping the rectangles from previous laps that will need to be queried from the database. |
Oct 2012
3:16pm, 23 Oct 2012
3,102 posts
|
runningmumof3boys
I don't think even the crow fly route from me in st Neots is 49 miles to Farnham Surrey. Not when it's 60miles Down A1 to outer London ?! |
Oct 2012
3:18pm, 23 Oct 2012
6,473 posts
|
McGoohan
When I do that race finder thing it draws a circle X miles around my home. Does your circle include Farnham RM?
|
Oct 2012
4:27pm, 23 Oct 2012
11,841 posts
|
fetcheveryone
Sprouty - point taken - it could effectively be making a similar query over and over. It's definitely something worth thinking about, but I'm not sure it affects so many routes that it will end up having a negative impact overall. So far I've been doing all my testing and profiling on one 11 mile route, for consistency (making sure that to switch off those parts of the process that would remove any markers, and ensuring that none of the queries I'm using get cached by mysql). I have a function that's set up so that I can vary N, but I've also been able to profile the other parts of the process, and I've picked up some nice improvements already: 1) I was using the split() function to convert a comma-separated latitude and longitude into two separate variables. It turns out that explode() is umpteen times faster, as well as not being deprecated ![]() 2) Reducing the number of returned markers has a nice impact on the subsequent checking process. Each returned marker is currently checked against each point from the route (yeah, I know), so this has the potential to be another big saving. 3) When checking proximity between the points on the route and markers, I was calculating the exact distance between the two - this meant 11 multiplications, five divisions, one minus, one add, two sines, three cosines, and one acosine. Accurate, but unnecessary. Just checking the latitude, and returning 'false' for anything ridiculous, and then doing the same for longitude, made the proximity checking element about 42% faster. To take my 11 mile circular loop as an example - the processing on my test box (which isn't as powerful as the server by a long way) was taking a median of 28.7 seconds to process, pulling in 1508 markers for testing (and hitting just 222 of them). Changing to 'explode' brought this time down to 25.1s, and adding the proximity sanity check brought this down further to 10.1s. Using an N of 20 (i.e. breaking the route into 20 equal chunks) reduced the number of markers being tested down to 541, and the processing time down to 3.87 seconds. More testing now, with different types of route (out-and-backs, laps, point to point, horizontal, diagonal etc), and in different parts of the country (Hebrides, Hyde Park). Having fun ![]() |
Oct 2012
4:40pm, 23 Oct 2012
18,299 posts
|
HappyG(rrr)
Good work that man. That's a hooge saving. You are Code Warrior! :-)G
|
Oct 2012
4:52pm, 23 Oct 2012
4,161 posts
|
sprouty76
Sounds like you're using the spherical law of cosines - if you already know the points being compared are close by (which you do in this case), do you really need to take curvature of the earth into account?
|
Oct 2012
4:56pm, 23 Oct 2012
11,842 posts
|
fetcheveryone
Can you point me at the simplified formula? (I'm just testing a 30 mile route that goes out of Manchester and back in. With no modifications it just falls over when the script times out after 5 mins (undoubtedly quicker on the server), having found 7017 markers. I'm adding my modifications one at a time to see how much they help). |
Oct 2012
5:01pm, 23 Oct 2012
4,162 posts
|
sprouty76
I was having a glance through this: movable-type.co.uk , in particular the bit about equirectangular approximation.
|
Oct 2012
5:06pm, 23 Oct 2012
10,843 posts
|
Stander
You just made that long word up.
|
Oct 2012
5:07pm, 23 Oct 2012
4,163 posts
|
sprouty76
It's a perfectly cromulent word.
|
Related Threads
-
In 5 words or less, start a fight (without politics) Mar 2025
-
thread for misanthropes Jan 2025
-
Fleecy-worthy insults Feb 2021
-
Room 101 Apr 2017
-
worst-dressed runner Mar 2014
-
That annoying Fetch popup Mar 2022
-
I can’t like anything anymore..... May 2019
-
What or who do you hate but everybody else seems to love?? Jul 2025
-
What really grinds your gears? Jul 2025
-
Things you want to say but can't Jul 2025
Report This Content
You can report any content you believe to be unsafe. Please let me know why you believe this content is unsafe by choosing a category below.
Thank you for your report. The content will be assessed as soon as possible.