Skip to content

Commit

Permalink
Improve performance of terms query for non-decimal numbers (#66909)
Browse files Browse the repository at this point in the history
Benchmarking terms query (10000+ terms) on long type, 
shows that the code part costing most CPU is when trying to judge
whether terms have a decimal part because a double mod is executed
for each number, regardless of if it has a decimal part. 

Adding a check before the mod take place to exclude non-decimal
numbers.
  • Loading branch information
gf2121 committed Jan 20, 2021
1 parent 1e14a01 commit c32f8b1
Showing 1 changed file with 6 additions and 0 deletions.
Expand Up @@ -751,6 +751,12 @@ Number valueForSearch(Number value) {
* Returns true if the object is a number and has a decimal part
*/
public static boolean hasDecimalPart(Object number) {
if (number instanceof Byte
|| number instanceof Short
|| number instanceof Integer
|| number instanceof Long) {
return false;
}
if (number instanceof Number) {
double doubleValue = ((Number) number).doubleValue();
return doubleValue % 1 != 0;
Expand Down

0 comments on commit c32f8b1

Please sign in to comment.