danrosher commented on PR #940:
URL: https://github.com/apache/solr/pull/940#issuecomment-1192560375

   > I'm a little confused as to what the sloppyAsin results are...
   > 
   > From your tests, we should still prefer NVector with MacLaurian expansion 
at 17 terms over using Sloppy Haversine, right? Is Sloppy Asin using NVector 
with no series expansion for the trig and instead the lookup tables from Sloppy 
Math? Which gives us the 40cm accuracy at _almost_ the original 10 term 
expansion performance level?
   
   We calculate the Great circle distance as `d=R*acos(a.b)` where d = 
distance, R = radius, and a,b are NVectors (a.b is the scalar dot product)
   
   We also know `acos(x) = pi/2-asin(x)`
   
   So I compared FastMath.acos (with 17 terms) with SloppyMath.asin, and found 
that FastMath.acos with 17 terms is 1.3x slower than SloppyMath.asin.
   
   This is what I meant with FastInvTrigBenchmark.sloppyAsin
   
   so SloppyMath.asin, at the required precision, is faster than FastMath.acos, 
   
   So I was thinking of abandoning FastMath.acos in favour of SloppyMath.asin, 
what do you think?
   
   > Can we do a similar trick to split the calculation to get an n-vector sort 
key and an n-vector meters and get even more speedup for the cases where we 
don't care about absolute distances?
   
   Yes! From looking at the acos plot ( 
https://www.wolframalpha.com/input?i2d=true&i=acos%5C%2840%29x%5C%2841%29 ) 
it's a 1 to 1 function, so well suited for comparison. I did a quick test which 
confirmed that the dot product is enough for comparison between values (which 
is all we need to do, as we cache the nvectors in the NVectorField). So we then 
have the following benchmark (with NVectorSortKey as this comparison and the 
fastest) :
   
   ```
   Benchmark                                   (num_points)  Mode  Cnt    Score 
  Error  Units
   FastInvTrigBenchmark.NVectorSortKey              2000000  avgt    2   13.846 
         ms/op
   FastInvTrigBenchmark.acosBM10                    2000000  avgt    2   45.620 
         ms/op
   FastInvTrigBenchmark.acosBM17                    2000000  avgt    2   68.673 
         ms/op
   FastInvTrigBenchmark.fastMathAcosBM              2000000  avgt    2  249.075 
         ms/op
   FastInvTrigBenchmark.haversineBM                 2000000  avgt    2  289.814 
         ms/op
   FastInvTrigBenchmark.mathAcosBM                  2000000  avgt    2  304.411 
         ms/op
   FastInvTrigBenchmark.mathAsin                    2000000  avgt    2  323.126 
         ms/op
   FastInvTrigBenchmark.sloppyAsin                  2000000  avgt    2   49.749 
         ms/op
   FastInvTrigBenchmark.sloppyHaversinMeters        2000000  avgt    2  135.847 
         ms/op
   FastInvTrigBenchmark.sloppyHaversinSortKey       2000000  avgt    2   82.149 
         ms/op
   ```
   
   So in Solr perhaps we can use NVectorSortKey for sort comparisons then.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to