On Tue, 4 Nov 2025 10:51:58 GMT, Oli Gillespie <[email protected]> wrote:

>> jengebr has updated the pull request incrementally with one additional 
>> commit since the last revision:
>> 
>>   Adding direct unit tests, minor revisions to optimizations
>
> test/micro/org/openjdk/bench/java/util/ArrayListBulkOpsBenchmark.java line 60:
> 
>> 58: @Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
>> 59: @Fork(value = 1, jvmArgs = { "-XX:+UseParallelGC", "-Xmx3g" })
>> 60: public class ArrayListBulkOpsBenchmark {
> 
> You might find a layout like this a bit neater:
> 
> 
> @State(Scope.Benchmark)
> public class ArrayListBulkOpsBench {
>     @Param({"0", "1", "5", "75"})
>     int size;
> 
>     @Param({"ArrayList", "LinkedList"})
>     String type;
> 
>     @Param({ "false", "true" })
>     private boolean poison;
> 
>     List<String> source;
> 
>     @Setup(Level.Trial)
>     public void setup() {
>         switch (type) {
>             case "ArrayList" -> source = new ArrayList<>(size);
>             case "LinkedList" -> source = new LinkedList<>();
>         }
>         for (int i = 0; i < size; i++) source.add("key" + i);
>         if (poison) poisonCallSites();
>     }
> 
>     @Benchmark
>     public ArrayList<String> addAll() {
>         ArrayList<String> result = new ArrayList<>(size);
>         result.addAll(source);
>         return result;
>     }
> 
>     static void poisonCallSites() {
>         HashMap<String, String> hashMapSource = new HashMap<>();
>         TreeSet<String> treeSetSource = new TreeSet<>();
>         WeakHashMap<String, String> weakHashMapSource = new WeakHashMap<>();
>         for (int i = 0; i < 75; i++) {
>             hashMapSource.put("key" + i, "value" + i);
>             treeSetSource.add("key" + i);
>             weakHashMapSource.put("key" + i, "value" + i);
>         }
>         // Poison ArrayList.addAll() with different Collection types
>         for (int i = 0; i < 40_000; i++) {
>             ArrayList<Object> temp = new ArrayList<>();
>             temp.addAll(hashMapSource.entrySet());
>             temp.addAll(treeSetSource);
>             temp.addAll(weakHashMapSource.keySet());
>         }
>     }
> 
>     @State(Scope.Benchmark)
>     public static class SingletonSet {
>         Set<String> singletonSetSource = Collections.singleton("key");
> 
>         @Param({ "false", "true" })
>         private boolean poison;
> 
>         @Setup(Level.Trial)
>         public void setup() {
>             if (poison) poisonCallSites();
>         }
> 
>         @Benchmark
>         public ArrayList<String> addAllSingletonSet() {
>             ArrayList<String> result = new ArrayList<>(1);
>             result.addAll(singletonSetSource);
>             return result;
>         }
>     }
> }
> 
> 
> addAll will be run against all permutations of size/type/poison. 
> addAllSingletonSet will just be run against false/...

I find it much neater, thank you - adopted in the latest revision.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/28116#discussion_r2491658900

Reply via email to