RFR: 8274276: Cache normalizedBase URL in URLClassPath.FileLoader [v2]

Daniel Fuchs dfuchs at openjdk.java.net
Mon Sep 27 17:08:06 UTC 2021


On Fri, 24 Sep 2021 11:50:21 GMT, Сергей Цыпанов <github.com+10835776+stsypanov at openjdk.org> wrote:

>> Currently on each invocation of `URLClassPath.FileLoader.getResource()` `normalizedBase` URL is recalculated using same final `baseURL` from parent class. This can be avoided giving significant improvement in memory consumption. Consider the benchmark:
>> 
>> @State(Scope.Benchmark)
>> @BenchmarkMode(Mode.AverageTime)
>> @OutputTimeUnit(TimeUnit.NANOSECONDS)
>> @Fork(jvmArgsAppend = {"-Xms2g", "-Xmx2g"})
>> public class URLClassPathBenchmark {
>>     private final ClassLoader classLoader = getClass().getClassLoader();
>> 
>>     @Benchmark
>>     public URL getResource() {
>>         return classLoader.getResource("file:./config/application.properties");
>>     }
>> }
>> 
>> it demonstrates improvement brought in by this patch:
>> 
>> before
>> Benchmark                                                           Mode  Cnt     Score     Error   Units
>> URLClassPathBenchmark.getResource                                   avgt   50  2840,746 ±  22,206   ns/op
>> URLClassPathBenchmark.getResource:·gc.alloc.rate                    avgt   50   645,313 ±   8,072  MB/sec
>> URLClassPathBenchmark.getResource:·gc.alloc.rate.norm               avgt   50  2403,258 ±  17,639    B/op
>> URLClassPathBenchmark.getResource:·gc.churn.G1_Eden_Space           avgt   50   656,624 ± 116,090  MB/sec
>> URLClassPathBenchmark.getResource:·gc.churn.G1_Eden_Space.norm      avgt   50  2450,175 ± 440,011    B/op
>> URLClassPathBenchmark.getResource:·gc.churn.G1_Survivor_Space       avgt   50     0,123 ±   0,149  MB/sec
>> URLClassPathBenchmark.getResource:·gc.churn.G1_Survivor_Space.norm  avgt   50     0,459 ±   0,556    B/op
>> URLClassPathBenchmark.getResource:·gc.count                         avgt   50    67,000            counts
>> URLClassPathBenchmark.getResource:·gc.time                          avgt   50   117,000                ms
>> 
>> after
>> Benchmark                                                           Mode  Cnt     Score    Error   Units
>> URLClassPathBenchmark.getResource                                   avgt  100  2596,719 ±  9,786   ns/op
>> URLClassPathBenchmark.getResource:·gc.alloc.rate                    avgt  100   448,780 ±  1,684  MB/sec
>> URLClassPathBenchmark.getResource:·gc.alloc.rate.norm               avgt  100  1528,040 ±  0,005    B/op
>> URLClassPathBenchmark.getResource:·gc.churn.G1_Eden_Space           avgt  100   479,905 ± 23,369  MB/sec
>> URLClassPathBenchmark.getResource:·gc.churn.G1_Eden_Space.norm      avgt  100  1634,314 ± 79,821    B/op
>> URLClassPathBenchmark.getResource:·gc.churn.G1_Survivor_Space       avgt  100     0,101 ±  0,097  MB/sec
>> URLClassPathBenchmark.getResource:·gc.churn.G1_Survivor_Space.norm  avgt  100     0,345 ±  0,329    B/op
>> URLClassPathBenchmark.getResource:·gc.count                         avgt  100    98,000           counts
>> URLClassPathBenchmark.getResource:·gc.time                          avgt  100   218,000               ms
>
> Сергей Цыпанов has updated the pull request incrementally with one additional commit since the last revision:
> 
>   8274276: Make URLClassPath.Loader.getBaseURL() final

OK - LGTM. I have run tier1 and tier2 on your changes in our CI and nothing unexpected came up.

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

Marked as reviewed by dfuchs (Reviewer).

PR: https://git.openjdk.java.net/jdk/pull/5677


More information about the core-libs-dev mailing list