On Fri, 24 Sep 2021 10:35:54 GMT, Сергей Цыпанов 
<github.com+10835776+stsypa...@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

This pull request has now been integrated.

Changeset: 94f5e807
Author:    Sergey Tsypanov <sergei.tsypa...@yandex.ru>
Committer: Daniel Fuchs <dfu...@openjdk.org>
URL:       
https://git.openjdk.java.net/jdk/commit/94f5e807c91674cf79e543a66cff1819206a790b
Stats:     5 lines in 1 file changed: 2 ins; 1 del; 2 mod

8274276: Cache normalizedBase URL in URLClassPath.FileLoader

Reviewed-by: dfuchs

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

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

Reply via email to