On Fri, 13 Nov 2026 18:14:53 GMT, Daniel Fuchs <[email protected]> wrote:

> Please find here a fix that improves URL and URI normalization algorithm. The 
> patch introduces a new static package-private normalize method in 
> java.net.URI that both URL and URI can share. The new method is based on the 
> pre-existing URI normalization algorithm, but avoids multiple backtacking 
> passes in the presence of .. segments.
> 
> This is globally similar to what was done for Path in 
> https://github.com/openjdk/jdk/pull/33799
> 
> When applying normalization, `URLStreamHandler` now uses the shared method 
> instead of rolling up its own.
> The `jar:` `Handler` now also uses the new method to normalize the resource 
> path (after the bang `!` separator) 
> 
> URI normalization output remained unchanged, but this patch revealed a few 
> corner case bugs in the existing URL normalization which can be observed and 
> have been fixed along. A system property 
> `jdk.net.urlDisableNormalizationOptimization=true|false` is introduced to 
> revert to the old behaviour. 
> A CSR will be logged to cover the addition of this new system property.
> 
> I also have added a micro-benchmark for both URL and URI, taking inspiration 
> from the micro-benchmark in https://github.com/openjdk/jdk/pull/33799. I have 
> pasted the [results in a 
> comment](https://github.com/openjdk/jdk/pull/33898#issuecomment-6922625690) 
> in this PR.
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

Benchmark comparison results (less is better):

URL Normalize


name                   count               before us/op          after us/op
absoluteLeadingDotDot     16          0.037 (+/- 0.004)    0.037 (+/- 0.015)
absoluteLeadingDotDot   1024          0.339 (+/- 0.041)    0.341 (+/- 0.045)
absoluteLeadingDotDot   8192          2.460 (+/- 0.664)    2.450 (+/- 0.311)
leadingDots               16          0.416 (+/- 0.045)    0.175 (+/- 0.013)
leadingDots             1024        91.944 (+/- 34.603)    6.292 (+/- 0.221)
leadingDots             8192     5969.509 (+/- 676.707)   55.367 (+/- 3.317)
nestedDotDot              16          0.576 (+/- 0.037)    0.321 (+/- 0.004)
nestedDotDot            1024      806.748 (+/- 466.126)   15.378 (+/- 1.859)
nestedDotDot            8192  64011.767 (+/- 14343.020)  147.617 (+/- 0.371)
noDots                    16          0.116 (+/- 0.010)    0.112 (+/- 0.021)
noDots                  1024          3.037 (+/- 0.383)    3.003 (+/- 0.089)
noDots                  8192         24.871 (+/- 0.460)   23.983 (+/- 0.997)
relativeLeadingDotDot     16          0.276 (+/- 0.013)    0.202 (+/- 0.088)
relativeLeadingDotDot   1024         44.411 (+/- 3.656)    8.318 (+/- 0.429)
relativeLeadingDotDot   8192     3099.131 (+/- 143.499)   70.161 (+/- 3.129)


URI Normalize


name                   count             before us/op           after us/op
absoluteLeadingDotDot     16        0.087 (+/- 0.006)     0.091 (+/- 0.002)
absoluteLeadingDotDot   1024        4.643 (+/- 0.698)     4.772 (+/- 0.054)
absoluteLeadingDotDot   8192      36.106 (+/- 16.246)   38.981 (+/- 29.784)
leadingDots               16        0.174 (+/- 0.009)     0.183 (+/- 0.014)
leadingDots             1024        8.568 (+/- 0.454)     8.823 (+/- 1.323)
leadingDots             8192      77.898 (+/- 27.558)   72.290 (+/- 23.298)
nestedDotDot              16        0.483 (+/- 0.054)     0.454 (+/- 0.021)
nestedDotDot            1024      186.986 (+/- 4.383)    26.298 (+/- 1.286)
nestedDotDot            8192  11779.372 (+/- 254.646)  206.847 (+/- 65.985)
noDots                    16        0.178 (+/- 0.011)     0.180 (+/- 0.015)
noDots                  1024        9.052 (+/- 0.731)     9.317 (+/- 0.197)
noDots                  8192      74.838 (+/- 19.748)    74.604 (+/- 0.361)
relativeLeadingDotDot     16        0.262 (+/- 0.049)     0.248 (+/- 0.021)
relativeLeadingDotDot   1024       13.395 (+/- 1.081)    12.679 (+/- 0.684)
relativeLeadingDotDot   8192     114.746 (+/- 14.861)   105.379 (+/- 5.797)

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

PR Comment: https://git.openjdk.org/jdk/pull/33898#issuecomment-6922625690

Reply via email to