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

Call refreshScope() once when saving all contexts #8205

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

double16
Copy link

When updating context information, ZAP calls saveAllContexts(). Each context save results in a call to refreshScope(). This is unnecessary. This PR calls refreshScope() after all contexts are saved.

In addition, a performance hit compiling a regex repeatedly was found and fixed.

@thc202
Copy link
Member

thc202 commented Nov 21, 2023

Be good to add tests.

@thc202
Copy link
Member

thc202 commented Nov 21, 2023

In addition, a performance hit compiling a regex repeatedly was found and fixed.

Do you have numbers? (Just curiosity.)

@double16
Copy link
Author

In addition, a performance hit compiling a regex repeatedly was found and fixed.

Do you have numbers? (Just curiosity.)

image

Nothing big. I think I read the wrong number, but still good practice to pre-compile.

@double16
Copy link
Author

Be good to add tests.

refreshScope() is only called when the view is initialized. I didn't see anything that would mock that in SessionUnitTest. Ideas?

@thc202
Copy link
Member

thc202 commented Nov 21, 2023

Nothing big. I think I read the wrong number, but still good practice to pre-compile.

Thank you. Agreed.

refreshScope() is only called when the view is initialized. I didn't see anything that would mock that in SessionUnitTest. Ideas?

You can mock the View, though given the EDT is in use probably something to go under src/testGui/.

@double16
Copy link
Author

It looks like the only way to verify refreshScope() is called is to check for side effects in the site tree unless the method is made package-private. How do you feel about that?

@double16
Copy link
Author

It looks like the only way to verify refreshScope() is called is to check for side effects in the site tree unless the method is made package-private. How do you feel about that?

Making refreshScope() package private would make adding the tests easier. Adding tests into testGui/ looks like a significant copy and paste of setup code from test/ to testGui/ . I don't want to do that work if it's not desired. Can someone comment on direction?

@double16
Copy link
Author

recheck

@thc202 thc202 closed this Feb 23, 2024
@thc202 thc202 reopened this Feb 23, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Feb 23, 2024
@zaproxy zaproxy unlocked this conversation Feb 23, 2024
@kingthorin
Copy link
Member

Is this old enough that it needs rebase to properly pickup CLA?

@thc202
Copy link
Member

thc202 commented Feb 23, 2024

No.

@thc202
Copy link
Member

thc202 commented Feb 23, 2024

#8205 (comment)

Exposing the method would not make much difference as we can't still tell if it's called or not, we should check that through sessionScopeChanged instead.

Regarding the duplication, that should not be needed as testGui should have visibility into test (if not that should be changed rather than duplicate).

Copy link
Member

Choose a reason for hiding this comment

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

Should have a ZAP comment after the license header (same for Session class).

@@ -114,6 +114,7 @@ public abstract class HttpHeader implements java.io.Serializable {
public static final String REFRESH = "refresh";
public static final Pattern patternCRLF = Pattern.compile("\\r\\n", Pattern.MULTILINE);
public static final Pattern patternLF = Pattern.compile("\\n", Pattern.MULTILINE);
private static final Pattern patternHeaderLF = Pattern.compile("(?<!\\r)\\n", Pattern.MULTILINE);
Copy link
Member

Choose a reason for hiding this comment

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

PATTERN_NEWLINES

Copy link
Member

Choose a reason for hiding this comment

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

As well as or instead of multi?

Copy link
Member

Choose a reason for hiding this comment

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

That's for the name of the constant.

…ment

Signed-off-by: Patrick Double <pat@patdouble.com>
Signed-off-by: Patrick Double <pat@patdouble.com>
@double16 double16 force-pushed the multiple-context-refresh-performance branch from 5a40aa7 to c38b3db Compare February 23, 2024 18:31
@double16
Copy link
Author

double16 commented Mar 7, 2024

Regarding the duplication, that should not be needed as testGui should have visibility into test (if not that should be changed rather than duplicate).

As far as I can tell testGui does not have visibility into test. IDEA doesn't recognize testGui as a source folder either, but the testGui task is recognized. I can't figure out how to get testGui to depend on the classpath of test. I've tried:

configurations {
    testGuiImplementation {
        extendsFrom(testImplementation.get())
    }
    testGuiRuntimeOnly {
        extendsFrom(testRuntimeOnly.get())
    }
}

but it doesn't help. If you know, could you post the gradle code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

3 participants