kaivalnp opened a new pull request, #15293:
URL: https://github.com/apache/lucene/pull/15293

   ### Description
   
   Intermediate cast from `int` -> `float` -> `int` in the byte vector specific 
[`cosineBody`](https://github.com/apache/lucene/blob/a4ebe984087cf62e3f8d96a53b2e7ebe96172500/lucene/core/src/java25/org/apache/lucene/internal/vectorization/PanamaVectorUtilSupport.java#L695)
 function(s) loses precision.
   
   This happens for integers >= 2^24, because IEEE 754 single-precision floats 
use 24 bits to represent the integer part.
   
   For example, when `16777217` is cast to `float` and back to `int`, it yields 
`16777216`.
   
   This also avoids CPU cycles related to casting. 
[`VectorUtilBenchmark`](https://github.com/apache/lucene/blob/a4ebe984087cf62e3f8d96a53b2e7ebe96172500/lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/VectorUtilBenchmark.java#L46)
 shows minor but consistent speedup:
   
   `main`
   
   ```
   Benchmark                               (size)   Mode  Cnt  Score   Error   
Units
   VectorUtilBenchmark.binaryCosineVector    1024  thrpt   15  4.782 ± 0.007  
ops/us
   ```
   
   This PR
   
   ```
   Benchmark                               (size)   Mode  Cnt  Score   Error   
Units
   VectorUtilBenchmark.binaryCosineVector    1024  thrpt   15  4.885 ± 0.002  
ops/us
   ```


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