RFR: 8321283: Reuse StringLatin1::equals in regionMatches
Francesco Nigro
duke at openjdk.org
Wed Nov 26 20:14:15 UTC 2025
On Mon, 4 Dec 2023 17:11:58 GMT, Chen Liang <liach at openjdk.org> wrote:
>> This improvement has been found on https://github.com/vert-x3/vertx-web/pull/2526.
>>
>> It can potentially affect the existing ArraysSupport.mismatch caller code-path performance ie requires investigation.
>
> src/java.base/share/classes/java/lang/String.java line 2185:
>
>> 2183: byte[] ov = other.value;
>> 2184: if (coder == otherCoder) {
>> 2185: if ((ooffset | toffset) == 0 && len == (tv.length >> coder) && ov.length == tv.length) {
>
> Just curious, is `(ooffset | toffset) == 0` more efficient than `ooffset == 0 && toffset== 0`?
It can be, depending the probability of happening for both and if/where their caller is inlined (presenting itself into different addresses, basically): conditions easy to predict are very cheap, but if not, can have some performance penalties.
An `|` between register is super cheap, instead: the same tecnique has been used at https://github.com/openjdk/jdk/blob/a26f7c03c72e4efe6d3219d294294c554aebc631/src/hotspot/share/utilities/copy.cpp#L215 which is supposed to be another hot-path, probably for similar reasons.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/16933#discussion_r1414227453
More information about the core-libs-dev
mailing list