slinkydeveloper commented on a change in pull request #18632:
URL: https://github.com/apache/flink/pull/18632#discussion_r810936091



##########
File path: 
flink-table/flink-table-common/src/main/java/org/apache/flink/table/utils/ThreadLocalCache.java
##########
@@ -75,4 +76,13 @@ protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
             return this.size() > maxSize;
         }
     }
+
+    public static <K, V> ThreadLocalCache<K, V> of(Function<K, V> creator) {

Review comment:
       Tried this:
   
   ```java
   @Fork(1)
   public class MyBenchmark {
   
       @State(Scope.Thread)
       public static class MyState {
           public int counter = 0;
   
           public ThreadLocalCache<Integer, String> 
threadLocalCacheWithoutLambda = new ThreadLocalCache<Integer, String>() {
               @Override
               public String getNewInstance(Integer integer) {
                   Blackhole.consumeCPU(2);
                   return integer.toString();
               }
           };
   
           public ThreadLocalCache<Integer, String> threadLocalCacheWithLambda 
= ThreadLocalCache.of(i -> {
               Blackhole.consumeCPU(2);
               return i.toString();
           });
       }
   
       @Benchmark
       public void testWithLambda(MyState myState, Blackhole blackhole) {
           
blackhole.consume(myState.threadLocalCacheWithLambda.getNewInstance(myState.counter++));
       }
   
       @Benchmark
       public void testWithoutLambda(MyState myState, Blackhole blackhole) {
           
blackhole.consume(myState.threadLocalCacheWithoutLambda.getNewInstance(myState.counter++));
       }
   
   }
   ```
   
   And here are the results:
   
   ```
   Benchmark                       Mode  Cnt         Score         Error  Units
   MyBenchmark.testWithLambda     thrpt    5  33187007.195 ± 3843963.071  ops/s
   MyBenchmark.testWithoutLambda  thrpt    5  34946890.368 ± 1586855.331  ops/s
   ```
   
   Can't really say anything about it, as results are too volatile on my 
machine, and probably if there is difference, it's very little  




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


Reply via email to