RFR: 8339290: Optimize ClassFile Utf8EntryImpl#writeTo [v2]
Claes Redestad
redestad at openjdk.org
Fri Aug 30 15:10:23 UTC 2024
On Fri, 30 Aug 2024 05:24:58 GMT, Shaojin Wen <swen at openjdk.org> wrote:
>> Use fast path for ascii characters 1 to 127 to improve the performance of writing Utf8Entry to BufferWriter.
>
> Shaojin Wen has updated the pull request incrementally with one additional commit since the last revision:
>
> add comments
Do you have any benchmark numbers of note to support this?
src/java.base/share/classes/java/lang/StringCoding.java line 37:
> 35: private StringCoding() { }
> 36:
> 37: public static boolean hasNegativeOrZeros(byte[] ba) {
Wait a second.. since you're only interested in and calling this when `s.coder == LATIN1` then values can't be negative. Which means all you really need is something like this:
public static boolean isLatin1WithNoZeros(String s) {
return s.isLatin() && s.indexOf(0) < 0;
}
`indexOf` have intrinsic support and might perform better than a simple for-loop.
src/java.base/share/classes/java/lang/System.java line 2598:
> 2596:
> 2597: public boolean hasNegativeOrZeros(String s) {
> 2598: return s.coder() == String.UTF16 || StringCoding.hasNegativeOrZeros(s.value());
Avoid adding logic to methods in `*Access` bridges, define `hasNonPositives(String s)` (or `isLatin1WithNoZeros(String)`) in `StringCoding` instead.
-------------
Changes requested by redestad (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/20772#pullrequestreview-2272579498
PR Review Comment: https://git.openjdk.org/jdk/pull/20772#discussion_r1738816044
PR Review Comment: https://git.openjdk.org/jdk/pull/20772#discussion_r1738821539
More information about the core-libs-dev
mailing list