RFR: 8314774: Optimize URLEncoder [v8]

Claes Redestad redestad at openjdk.org
Thu Aug 31 10:31:02 UTC 2023


On Thu, 24 Aug 2023 10:38:57 GMT, Glavo <duke at openjdk.org> wrote:

>> I mainly made these optimizations:
>> 
>> * Avoid allocating `StringBuilder` when there are no characters in the URL that need to be encoded;
>> * Implement a fast path for UTF-8.
>> 
>> In addition to improving performance, these optimizations also reduce temporary objects:
>> 
>> * It no longer allocates any object when there are no characters in the URL that need to be encoded;
>> * The initial size of StringBuilder is larger to avoid expansion as much as possible;
>> * For UTF-8, the temporary `CharArrayWriter`, strings and byte arrays are no longer needed.
>> 
>> The results of the `URLEncodeDecode` benchmark:
>> 
>> 
>> Before:
>> Benchmark                       (count)  (maxLength)  (mySeed)  Mode  Cnt  Score   Error  Units
>> URLEncodeDecode.testEncodeUTF8     1024         1024         3  avgt   15  5.587 ? 0.010  ms/op
>> 
>> After:
>> Benchmark                       (count)  (maxLength)  (mySeed)  Mode  Cnt  Score   Error  Units
>> URLEncodeDecode.testEncodeUTF8     1024         1024         3  avgt   15  3.582 ? 0.054  ms/op
>> 
>> 
>> I also updated the tests to add more test cases.
>
> Glavo has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Remove UTF-8 fast path

@minborg has a prototype for a immutable `BitSet` here: #15493. Early evaluation shows we can get a better speed-up using that than from replacing the `BitSet` with a `@Stable boolean[128]` that you're doing in this PR. 

So while it was a very helpful experiment -- which showed a performance issue with mutable `BitSet`s --  I think we want to roll back the various changes to `DONT_NEED_ENCODING` in this PR. Or wait until #15493 is done and use the ability to make a `BitSet` immutable (and easily constant-foldable).

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

PR Comment: https://git.openjdk.org/jdk/pull/15354#issuecomment-1700780003


More information about the net-dev mailing list