Skip to content

8274276: Cache normalizedBase URL in URLClassPath.FileLoader #5677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

stsypanov
Copy link
Contributor

@stsypanov stsypanov commented Sep 24, 2021

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

Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8274276: Cache normalizedBase URL in URLClassPath.FileLoader

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/5677/head:pull/5677
$ git checkout pull/5677

Update a local copy of the PR:
$ git checkout pull/5677
$ git pull https://git.openjdk.java.net/jdk pull/5677/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 5677

View PR using the GUI difftool:
$ git pr show -t 5677

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/5677.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 24, 2021

👋 Welcome back stsypanov! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Sep 24, 2021
@openjdk
Copy link

openjdk bot commented Sep 24, 2021

@stsypanov The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Sep 24, 2021
@mlbridge
Copy link

mlbridge bot commented Sep 24, 2021

Webrevs

Copy link
Member

@dfuch dfuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is calling an overidable method within a constructor, which might have unforeseen side effects. Can you make Loader::getBaseURL final? That would remove the concern.

@stsypanov
Copy link
Contributor Author

@dfuch Sure, done!

Copy link
Member

@dfuch dfuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@openjdk
Copy link

openjdk bot commented Sep 27, 2021

⚠️ @stsypanov the full name on your profile does not match the author name in this pull requests' HEAD commit. If this pull request gets integrated then the author name from this pull requests' HEAD commit will be used for the resulting commit. If you wish to push a new commit with a different author name, then please run the following commands in a local repository of your personal fork:

$ git checkout 8274276
$ git commit -c user.name='Preferred Full Name' --allow-empty -m 'Update full name'
$ git push

@openjdk
Copy link

openjdk bot commented Sep 27, 2021

@stsypanov This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8274276: Cache normalizedBase URL in URLClassPath.FileLoader

Reviewed-by: dfuchs

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 32 new commits pushed to the master branch:

  • 0865120: 8274345: make build-test-lib is broken
  • 75404ea: 8267636: Bump minimum boot jdk to JDK 17
  • 14100d5: 8274170: Add hooks for custom makefiles to augment jtreg test execution
  • daaa47e: 8274311: Make build.tools.jigsaw.GenGraphs more configurable
  • 2cffe4c: 8274326: [macos] Ensure initialisation of sun/lwawt/macosx/CAccessibility in JavaComponentAccessibility.m
  • 172900d: 8274255: Update javac messages to use "enum class" rather than "enum type"
  • b0983df: 8274074: SIGFPE with C2 compiled code with -XX:+StressGCM
  • 7436a77: 8274317: Unnecessary reentrant synchronized block in java.awt.Cursor
  • 7426fd4: 8274325: C4819 warning at vm_version_x86.cpp on Windows after JDK-8234160
  • e3aff8f: 8274289: jdk/jfr/api/consumer/TestRecordedFrameType.java failed with "RuntimeException: assertNotEquals: expected Interpreted to not equal Interpreted"
  • ... and 22 more: https://git.openjdk.java.net/jdk/compare/971aa353aae51222ca33ebfdd61b91672a6c871a...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@dfuch) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Sep 27, 2021
@stsypanov
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Sep 27, 2021
@openjdk
Copy link

openjdk bot commented Sep 27, 2021

@stsypanov
Your change (at version 937e6ae) is now ready to be sponsored by a Committer.

@dfuch
Copy link
Member

dfuch commented Sep 28, 2021

/sponsor

@openjdk
Copy link

openjdk bot commented Sep 28, 2021

Going to push as commit 94f5e80.
Since your change was applied there have been 45 commits pushed to the master branch:

  • b36881f: 8274383: JNI call of getAccessibleSelection on a wrong thread
  • be40373: 8274381: missing CAccessibility definitions in JNI code
  • 79865cd: 8274259: G1: assert(check_alignment(result)) failed: address not aligned: 0x00000008baadbabe after JDK-8270009
  • 961dcff: 8273581: Change the mechanism by which JDK loads the platform-specific FontManager class
  • 6a573b8: 8273508: Support archived heap objects in SerialGC
  • 3eca9c3: 8264707: HotSpot Style Guide should permit use of lambda
  • af50772: 8231640: (prop) Canonical property storage
  • ddc2627: 8273790: Potential cyclic dependencies between Gregorian and CalendarSystem
  • 633eab2: 8174819: java/nio/file/WatchService/LotsOfEvents.java fails intermittently
  • 8876eae: 8269685: Optimize HeapHprofBinWriter implementation
  • ... and 35 more: https://git.openjdk.java.net/jdk/compare/971aa353aae51222ca33ebfdd61b91672a6c871a...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot closed this Sep 28, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Sep 28, 2021
@openjdk
Copy link

openjdk bot commented Sep 28, 2021

@dfuch @stsypanov Pushed as commit 94f5e80.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@stsypanov stsypanov deleted the 8274276 branch September 28, 2021 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

2 participants