Skip to content
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

Optimize extractSetMethod(...) and findFunction(...) #1804

Merged
merged 9 commits into from
Feb 1, 2025

Conversation

ZZZank
Copy link
Contributor

@ZZZank ZZZank commented Jan 26, 2025

  • setter extracting is rewritten to do setter scanning in 1 pass instead of 2 passes
  • a helper method failFastConversionWeights(...) that can compute conversion weights in batch
  • computed weights from failFastConversionWeights(...) will now be cached to prevent computing weight again in preferSignature()

@ZZZank
Copy link
Contributor Author

ZZZank commented Jan 27, 2025

I've ran a test for these changes (https://github.com/ZZZank/rhino-mozilla/actions/runs/12994132974), seems to be working quite well

@gbrail
Copy link
Collaborator

gbrail commented Jan 28, 2025

This looks fine to me, although I don't consume this bit of Rhino functionality myself much anymore and it'd be nice to see if someone else could check it out.

Also, could you please run "./gradlew test testCodeCoverageReport" and take a look at the result (which is in tests/build/reports/jacoco/testCodeCoverageReport) for the parts that you changed?

I do see a big "we should never get here" in your code, and I won't worry as much about coverage there, but there are a few places where your new code checks for things and we never get there in the tests. It's not much but given how complex this code is I would feel better if you took at look at the coverage for the stuff you touched and see if you can cover as many of the edge cases as you can. Thanks!

@ZZZank
Copy link
Contributor Author

ZZZank commented Jan 29, 2025

Code Coverage report: https://github.com/ZZZank/rhino-mozilla/actions/runs/13013170787

I took a brief look into it, and it seems almost all modified codes are touched, except for line380~382:

->      if (firstBestFit < 0) {
->          // Nothing was found
->          return -1;
        } else if (extraBestFitsCount == 0) {
            // single best fit
            return firstBestFit;
        }

and line507~509:

        if (member.vararg) {
            typeLen--;
->          if (typeLen > args.length) {
->              return null;
            }
        } else {

I knew a way of testing them both, but I'm not familiar with Rhino Test System. So I will write down my plan here first, hopefully I can figure Rhino Test out or someone will help me.

First make a dummy class:

class VarArgDummy {
   public static void dummy(String s0, String s1, String s2, String... varArgs) {}
}

import it into Rhino as VarArgDummy, and call:

VarArgDummy.dummy("s0", "s1, but no s2")

It should throw an exception, and the aforementioned two pieces of codes will be touched. It will work like this:

// in findFunction(...)
        if (methodsOrCtors.length == 1) { // dummy() is the only method with such name
            if (failFastConversionWeights(args, methodsOrCtors[0]) == null) { //see below, returning null
                return -1; // code touched
            }

// In failFastConversionWeights(...)
        if (member.vararg) { // the method is vararg
            typeLen--; // typeLen was originally 4
            if (typeLen > args.length) { // typeLen is 3, args.length is 2
                return null; // code touched, back to findFunction(...)
            } 
        } else {

@gbrail
Copy link
Collaborator

gbrail commented Jan 30, 2025

Thanks for looking at that -- It'd be great to have a few more tests. I'd suggest looking at some of the tests in the "tests" package, especially the ones under "src/test/java/org/mozilla/javascript/test," for example, but basically any Junit test will work (most use Junit 4 but we support Junit 5 too).

You should also look at the "Utils" class in the "testutils" package, which will manage the Context properly (which is important) and also ensure that each test runs both in interpreted and in compiled mode.

@ZZZank
Copy link
Contributor Author

ZZZank commented Jan 31, 2025

code coverage report after adding tests: https://github.com/ZZZank/rhino-mozilla/actions/runs/13067986035 , the two branches mentioned above are covered

@gbrail
Copy link
Collaborator

gbrail commented Feb 1, 2025

Thanks! This looks good now!

@gbrail gbrail merged commit 5cc4aa1 into mozilla:master Feb 1, 2025
3 checks passed
@ZZZank ZZZank deleted the java-member-perf branch February 1, 2025 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants