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
…67752)

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.

(cherry picked from commit c32f8b1)

Co-authored-by: gf2121 <52390227+gf2121@users.noreply.github.com>
  • Loading branch information
matriv and gf2121 committed Jan 20, 2021
1 parent b4ce658 commit 70ce1e1
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 70ce1e1

Please sign in to comment.