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

    https://github.com/apache/activemq-artemis/pull/1752#discussion_r160003612
  
    --- Diff: 
artemis-commons/src/main/java/org/apache/activemq/artemis/utils/AbstractInterner.java
 ---
    @@ -0,0 +1,157 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements. See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License. You may obtain a copy of the License at
    + *
    + * http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.activemq.artemis.utils;
    +
    +import io.netty.buffer.ByteBuf;
    +import io.netty.util.internal.MathUtil;
    +import io.netty.util.internal.PlatformDependent;
    +
    +/**
    + * Thread-safe {@code <T>} interner.
    + * <p>
    + * Differently from {@link String#intern()} it contains a fixed amount of 
entries and
    + * when used by concurrent threads it doesn't ensure the uniqueness of the 
entries ie
    + * the same entry could be allocated multiple times by concurrent calls.
    + */
    +public abstract class AbstractInterner<T> {
    --- End diff --
    
    btw for the guava implementation i did i ran this very rudimentary test (I 
am not saying in anyway this is a true perf test, but just to provide something 
indicative), so it run for a while and take final run results from each idea to 
let jit some chance to do what ever it needs, and the array to hold objects is 
to simulate the objects sticking around for a bit, and give some gc pressure.
    
    
    ```
      public static void main(String... args) throws InterruptedException {
          
          byte[] testString = "hello".getBytes();
    
          
          int size = 10000000;
    
    
          int inx = 0;
          long start2 = 0;
          long end2 = 0;
          long start = 0;
          long end = 0;
          SimpleString[] array = new SimpleString[size * 10];
    
          
          
          for (int k = 0; k < 5; k++) {
             array = new SimpleString[size * 10];
             inx = 0;
    
             System.gc();
             Thread.sleep(1000);
    
             for (int j = 0; j < 10; j++) {
                start = System.nanoTime();
                for (int i = 0; i < size; i++) {
                   SimpleString simpleString = new SimpleString(testString);
                   array[inx] = simpleString;
                   inx++;
                }
                end = System.nanoTime();
             }
    
             array = new SimpleString[size * 10];
             inx = 0;
    
             System.gc();
             Thread.sleep(1000);
             for (int j = 0; j < 10; j++) {
                start2 = System.nanoTime();
                for (int i = 0; i < size; i++) {
                   SimpleString simpleString = 
SimpleString.toSimpleString(testString);
                   array[inx] = simpleString;
                   inx++;
                }
                end2 = System.nanoTime();
             }
          }
    
          System.out.println("new      " + (end-start));
          System.out.println("intern   " + (end2-start2));
    
       }
    ```
    
    outputs:
    
    new      35102118957
    intern   368258702



---

Reply via email to