richardstartin commented on a change in pull request #7402:
URL: https://github.com/apache/pinot/pull/7402#discussion_r703820532



##########
File path: 
pinot-common/src/main/java/org/apache/pinot/common/utils/PinotDataType.java
##########
@@ -776,30 +777,70 @@ public String toString(Object value) {
 
   // Mapping Java class type to PinotDataType, for SV and MV value separately.
   // OBJECT and OBJECT_ARRAY are default type for unknown Java types.
-  private static final Map<Class<?>, PinotDataType> SINGLE_VALUE_TYPE_MAP = 
new HashMap<Class<?>, PinotDataType>() {{
-    put(Boolean.class, BOOLEAN);
-    put(Byte.class, BYTE);
-    put(Character.class, CHARACTER);
-    put(Short.class, SHORT);
-    put(Integer.class, INTEGER);
-    put(Long.class, LONG);
-    put(Float.class, FLOAT);
-    put(Double.class, DOUBLE);
-    put(Timestamp.class, TIMESTAMP);
-    put(String.class, STRING);
-    put(byte[].class, BYTES);
-  }};
-
-  private static final Map<Class<?>, PinotDataType> MULTI_VALUE_TYPE_MAP = new 
HashMap<Class<?>, PinotDataType>() {{
-    put(Byte.class, BYTE_ARRAY);
-    put(Character.class, CHARACTER_ARRAY);
-    put(Short.class, SHORT_ARRAY);
-    put(Integer.class, INTEGER_ARRAY);
-    put(Long.class, LONG_ARRAY);
-    put(Float.class, FLOAT_ARRAY);
-    put(Double.class, DOUBLE_ARRAY);
-    put(String.class, STRING_ARRAY);
-  }};
+  private static final Function<Class<?>, PinotDataType> 
SINGLE_VALUE_TYPE_MAPPING = memoize(cls -> {

Review comment:
       Good call. Reordering the checks so the most common types come first 
(strings and numbers), I got a good speedup, but I think enough time has been 
spent on this already now; if the PR in its current state can't be accepted I 
suggest dropping it given the "low hanging fruit" nature of the change.
   
   ```
   HashMap
   Benchmark                                       Mode  Cnt    Score   Error   
Units
   PinotDataTypeMappingBenchmark.singleValueType  thrpt    5  167.105 ± 2.642  
ops/us
   
   ClassValue
   Benchmark                                       Mode  Cnt    Score   Error   
Units
   PinotDataTypeMappingBenchmark.singleValueType  thrpt    5  197.252 ± 7.364  
ops/us
   
   Plain if statements
   Benchmark                                       Mode  Cnt    Score    Error  
 Units
   PinotDataTypeMappingBenchmark.singleValueType  thrpt    5  316.590 ± 16.078  
ops/us
   ```
   ```java
   @State(Scope.Benchmark)
   public class PinotDataTypeMappingBenchmark {
   
     private Class[] _types;
   
     @Setup(Level.Trial)
     public void setup() {
       _types = new Class[]{
           String.class,
           Integer.class,
           String[].class,
           Double.class,
           Byte.class,
           Boolean.class,
           Long.class,
           Float.class,
           Class.class,
           int[].class,
           Double.class,
           Double.class,
           Double.class,
           double[].class,
           String.class,
           String.class,
           String.class,
           String.class,
           Boolean.class,
           Boolean.class,
           String.class,
           Integer.class,
           String[].class,
           Double.class,
           Byte.class,
           Boolean.class,
           Long.class,
           Float.class,
           Class.class,
           int[].class,
           Double.class,
           Double.class,
           Double.class,
           double[].class,
           String.class,
           String.class,
           String.class,
           String.class,
           Boolean.class,
           Boolean.class
       };
     }
   
     @Benchmark
     @OperationsPerInvocation(40)
     public void singleValueType(Blackhole bh) {
       for (Class<?> cls : _types) {
         bh.consume(PinotDataType.getSingleValueType(cls));
       }
     }
   
   }
   ```




-- 
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: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to