> 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 ------------- Changes: - all: https://git.openjdk.java.net/jdk/pull/5677/files - new: https://git.openjdk.java.net/jdk/pull/5677/files/dffc3301..937e6aee Webrevs: - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=5677&range=01 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=5677&range=00-01 Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod Patch: https://git.openjdk.java.net/jdk/pull/5677.diff Fetch: git fetch https://git.openjdk.java.net/jdk pull/5677/head:pull/5677 PR: https://git.openjdk.java.net/jdk/pull/5677