Github user sachouche commented on a diff in the pull request:

    https://github.com/apache/drill/pull/1001#discussion_r146952578
  
    --- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternContainsMatcher.java
 ---
    @@ -17,37 +17,166 @@
      */
     package org.apache.drill.exec.expr.fn.impl;
     
    -public class SqlPatternContainsMatcher implements SqlPatternMatcher {
    +public final class SqlPatternContainsMatcher implements SqlPatternMatcher {
       final String patternString;
       CharSequence charSequenceWrapper;
       final int patternLength;
    +  final MatcherFcn matcherFcn;
     
       public SqlPatternContainsMatcher(String patternString, CharSequence 
charSequenceWrapper) {
    -    this.patternString = patternString;
    +    this.patternString       = patternString;
         this.charSequenceWrapper = charSequenceWrapper;
    -    patternLength = patternString.length();
    +    patternLength            = patternString.length();
    +
    +    // The idea is to write loops with simple condition checks to allow 
the Java Hotspot achieve
    +    // better optimizations (especially vectorization)
    +    if (patternLength == 1) {
    +      matcherFcn = new Matcher1();
    --- End diff --
    
    I ran two types of tests to evaluate the generic vs custom method:
    Test1 - A match does exist
    o Custom method is 3x faster because the code will go to the "else" part
    o A nested loop is always slower than unrolled code (the loop is also 
correlated with the outer one); please refer to this article 
(https://en.wikipedia.org/wiki/Loop_unrolling) on the benefits of loop unrolling
    o Older match function performed in 59sec
    
    Test2- A match doesn't exist
    o Custom method and generic one perform in 15sec; this is because both 
perform a comparison and proceed to the next iteration
    o Older match function performed in 45sec 


---

Reply via email to