RFR: 8367005: ImageReader refactor caused performance regressions for startup and footprint [v2]
David Beaumont
duke at openjdk.org
Thu Sep 11 19:12:06 UTC 2025
On Thu, 11 Sep 2025 11:59:26 GMT, Claes Redestad <redestad at openjdk.org> wrote:
>> I think replacing `startsWith(String)` with `indexOf(char)` is dubious, since the latter is O(n) and the former O(1)
>>
>> If you _really_ need to squeeze out everything on startup then `(x.length() > 0 && x.charAt(0) == '/')` is slightly faster in the interpreter (the difference more or less disappears after JIT compilation). I'd keep using `startsWith("/")`.
>
> (Yes, `x.lastIndexOf('/', 0) == 0` is even faster for the interpreter, but let's keep it civil in these trying times.)
Oh good grief you're right, indexOf() == 0 is not a good idea. However, the good news is that I realized that could be removed (anything with / on the front leads to a // in the effective path and cannot resolve to anything.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/27203#discussion_r2342095004
More information about the core-libs-dev
mailing list