Re: RFR: 8287522: StringConcatFactory: Add in prependers and mixers in batches [v3]

2022-06-01 Thread ExE Boss
On Wed, 1 Jun 2022 13:03:38 GMT, Claes Redestad  wrote:

>> When generating `MethodHandle`-based concatenation expressions in 
>> `StringConcatFactory` we can reduce the number of classes generated at 
>> runtime by creating small batches of prependers and mixers before binding 
>> them into the root expression tree. 
>> 
>> Improvements on one-off tests are modest, while the improvement on 
>> bootstrapping stress tests can be substantial 
>> ([MixedStringCombinations.java](https://gist.github.com/cl4es/08fb581dece3a73e89bfa52337bc4248)):
>> 
>> | Build  |# classes|   Runtime   |
>> | --- | - |  --- |
>> | Baseline | 31119   | 2.942s |
>> | Patch  | 16208   | 1.958s |
>> 
>> An earlier version of this patch saw a regression in the 
>> `StringConcatFactoryBootstraps` microbenchmark. After some refactoring along 
>> with the optimizations in #8881 and #8923 that is no longer the case, and 
>> allocation pressure is down slightly compared to the baseline on such a 
>> repeat-the-same-bootstrap stress test:
>> 
>> Baseline:
>> 
>> Benchmark  Mode  Cnt 
>> Score  Error   Units
>> SCFB.makeConcatWithConstants   avgt5  
>> 2170.039 ?  117.441   ns/op
>> SCFB.makeConcatWithConstants:?gc.alloc.rate.norm   avgt5  
>> 3538.020 ?4.558B/op
>> 
>> This patch:
>> 
>> Benchmark  Mode  Cnt 
>> Score  Error   Units
>> SCFB.makeConcatWithConstants   avgt5  
>> 2144.807 ?  162.685   ns/op
>> SCFB.makeConcatWithConstants:?gc.alloc.rate.norm   avgt5  
>> 3184.943 ?4.495B/op
>
> Claes Redestad has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Improve bootstrap microbenchmark to include more shapes, reduce runtime

src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java line 674:

> 672: 1 + pos, 2 + pos, 3 + pos, 4 + pos // selected 
> arguments
> 673: );
> 674: }

This should probably also use a switch like the above:
Suggestion:

return switch (count) {
case 1 -> MethodHandles.foldArgumentsWithCombiner(mh, 0, mix,
1 + pos // selected arguments
);
case 2 -> MethodHandles.foldArgumentsWithCombiner(mh, 0, mix,
1 + pos, 2 + pos // selected arguments
);
case 3 -> MethodHandles.foldArgumentsWithCombiner(mh, 0, mix,
1 + pos, 2 + pos, 3 + pos // selected arguments
);
case 4 -> MethodHandles.foldArgumentsWithCombiner(mh, 0, mix,
1 + pos, 2 + pos, 3 + pos, 4 + pos // selected arguments
);
default -> throw new AssertionError(count);
}

-

PR: https://git.openjdk.java.net/jdk/pull/8855


Re: RFR: 8287522: StringConcatFactory: Add in prependers and mixers in batches [v3]

2022-06-01 Thread Claes Redestad
> When generating `MethodHandle`-based concatenation expressions in 
> `StringConcatFactory` we can reduce the number of classes generated at 
> runtime by creating small batches of prependers and mixers before binding 
> them into the root expression tree. 
> 
> Improvements on one-off tests are modest, while the improvement on 
> bootstrapping stress tests can be substantial 
> ([MixedStringCombinations.java](https://gist.github.com/cl4es/08fb581dece3a73e89bfa52337bc4248)):
> 
> | Build  |# classes|   Runtime   |
> | --- | - |  --- |
> | Baseline | 31119   | 2.942s |
> | Patch  | 16208   | 1.958s |
> 
> An earlier version of this patch saw a regression in the 
> `StringConcatFactoryBootstraps` microbenchmark. After some refactoring along 
> with the optimizations in #8881 and #8923 that is no longer the case, and 
> allocation pressure is down slightly compared to the baseline on such a 
> repeat-the-same-bootstrap stress test:
> 
> Baseline:
> 
> Benchmark  Mode  Cnt 
> Score  Error   Units
> SCFB.makeConcatWithConstants   avgt5  
> 2170.039 ?  117.441   ns/op
> SCFB.makeConcatWithConstants:?gc.alloc.rate.norm   avgt5  
> 3538.020 ?4.558B/op
> 
> This patch:
> 
> Benchmark  Mode  Cnt 
> Score  Error   Units
> SCFB.makeConcatWithConstants   avgt5  
> 2144.807 ?  162.685   ns/op
> SCFB.makeConcatWithConstants:?gc.alloc.rate.norm   avgt5  
> 3184.943 ?4.495B/op

Claes Redestad has updated the pull request incrementally with one additional 
commit since the last revision:

  Improve bootstrap microbenchmark to include more shapes, reduce runtime

-

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/8855/files
  - new: https://git.openjdk.java.net/jdk/pull/8855/files/263db625..4221b348

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk=8855=02
 - incr: https://webrevs.openjdk.java.net/?repo=jdk=8855=01-02

  Stats: 25 lines in 1 file changed: 19 ins; 1 del; 5 mod
  Patch: https://git.openjdk.java.net/jdk/pull/8855.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/8855/head:pull/8855

PR: https://git.openjdk.java.net/jdk/pull/8855