RFR: 8338930: StringConcatFactory static string concatenation strategy
ExE Boss
duke at openjdk.org
Sun Aug 25 04:33:39 UTC 2024
On Thu, 22 Aug 2024 11:50:02 GMT, Shaojin Wen <duke at openjdk.org> wrote:
> This is a follow-up to PR #20273, which improves performance when the number of parameters exceeds 20.
>
> When the number of parameters is large, the possibility of reuse will be lower, so we can use the static concat method and write the length and coder directly into the bytecode to solve the performance regression problem.
src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java line 1476:
> 1474: * coder = coder(this.coder, arg0, arg1, ... argN);
> 1475: */
> 1476: if (staticConcat) {
It might be better for this loop to only be ran when `staticConcat` is `true`:
Suggestion:
/*
* coder = coder(this.coder, arg0, arg1, ... argN);
*/
if (staticConcat) {
for (var constant : constants) {
coder |= JLA.stringCoder(constant);
length += constant.length();
}
src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java line 1711:
> 1709: */
> 1710: cb.iload(lengthSlot);
> 1711: for (int i = prependArgs.parameterCount() - 1; i >= (staticConcat ? 3 : 4); i--) {
The result of `staticConcat ? 3 : 4` should probably be stored in a local outside the loop:
Suggestion:
for (int i = prependArgs.parameterCount() - 1, end = staticConcat ? 3 : 4; i >= end; i--) {
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/20675#discussion_r1728578074
PR Review Comment: https://git.openjdk.org/jdk/pull/20675#discussion_r1728586732
More information about the core-libs-dev
mailing list