RFR: 8314774: Optimize URLEncoder [v11]

Glavo duke at openjdk.org
Mon Sep 18 22:31:07 UTC 2023


> 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 with a new target base due to a merge or a rebase. The pull request now contains 21 commits:

 - Merge branch 'openjdk:master' into url-encoder
 - Remove unused import
 - fix style
 - fix style
 - Merge remote-tracking branch 'origin/master' into url-encoder
 - Remove UTF-8 fast path
 - Update UTF8EncodeUtils
 - Add final modifier
 - Add @ForceInline
 - Use byte[] in UTF8EncodeUtils
 - ... and 11 more: https://git.openjdk.org/jdk/compare/373e37bf...0362126e

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

Changes: https://git.openjdk.org/jdk/pull/15354/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=15354&range=10
  Stats: 162 lines in 2 files changed: 38 ins; 75 del; 49 mod
  Patch: https://git.openjdk.org/jdk/pull/15354.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/15354/head:pull/15354

PR: https://git.openjdk.org/jdk/pull/15354


More information about the net-dev mailing list