[10] RFR: 8176041: Optimize handling of comment lines in Properties$LineReader.readLine
Aleksey Shipilev
shade at redhat.com
Wed Mar 1 15:40:58 UTC 2017
On 03/01/2017 04:34 PM, Claes Redestad wrote:
> the properties line reader has some relevance to startup, e.g.,
> when reading the java.security file, and as more documentation
> content has been added to this file it has been made apparent
> that the handling of comment lines is inefficient due to treating
> every character after a comment line marker ('#' or '!') as any
> other character (writes it to an internal buffer etc) when a
> fast-path consuming the rest of the line would do.
>
> Bug: https://bugs.openjdk.java.net/browse/JDK-8176041
> Webrev: http://cr.openjdk.java.net/~redestad/8176041/jdk.01
The idea looks fine.
I think you can go further and unswitch the loop, saving branch in a hot loop,
and using byte comparisons (may require some work to do efficient byte-char
comparisons):
if (inStream != null) {
while (inOff < inLimit) {
byte b = inByteBuf[inOff++];
if (b == '\n' || b == '\r' || b == '\\') {
break;
}
}
} else {
while (inOff < inLimit) {
c = inCharBuf[inOff++];
if (c == '\n' || c == '\r' || c == '\\') {
break;
}
}
}
Thanks,
-Aleksey
More information about the core-libs-dev
mailing list