RFR: 8314774: Optimize URLEncoder [v10]

Claes Redestad redestad at openjdk.org
Mon Sep 18 22:14:40 UTC 2023


On Wed, 6 Sep 2023 13:37:27 GMT, Claes Redestad <redestad at openjdk.org> wrote:

>> src/java.base/share/classes/java/net/URLEncoder.java line 140:
>> 
>>> 138:     }
>>> 139: 
>>> 140:     private static void encodeByte(StringBuilder out, byte b) {
>> 
>> This routine is basically 
>> 
>> out.append('%');
>> HexFormat.of().withUpperCase().toHexDigits(out, b);
>> 
>> If this doesn't perform as well (with or without `HexFormat.of().withUpperCase()` cached in a static field) then that might be worth looking into.
>
> I took a look at `HexFormat` and found that performance could be touched up a notch: #15591

#15591 has been pushed, and when I test changing `encodeByte` to this:

    private static void encodeByte(StringBuilder out, byte b) {
        out.append('%');
        HexFormat.of().withUpperCase().toHexDigits(out, b);
    }

... results are performance neutral:

Name                           (unchanged) Cnt  Base   Error   Test   Error  Unit   Diff%
URLEncodeDecode.testEncodeUTF8           0  15 2,069 ± 0,027  1,943 ± 0,004 ms/op    6,1% (p = 0,000*)
URLEncodeDecode.testEncodeUTF8          75  15 0,946 ± 0,025  0,920 ± 0,002 ms/op    2,7% (p = 0,001*)
URLEncodeDecode.testEncodeUTF8         100  15 0,484 ± 0,008  0,473 ± 0,016 ms/op    2,3% (p = 0,019 )
  * = significant

Feel free to sync up with master and use that, since it simplifies and consolidates the implementation. Either way you decide I can approve and sponsor this.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/15354#discussion_r1329331465


More information about the net-dev mailing list