-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Store annotationType.getSimpleName() in a field in BooleanExecutionCondition
#4619
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
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
annotationType.getSimpleName() to improve performance
sbrannen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Congratulations on submitting your first PR for JUnit! 👍
My PR optimizes the performance and readability of the BooleanExecutionCondition class by memoizing the annotationType.SimpleName method.
There is no performance gain with that change since annotationType.getSimpleName() is only invoked once.
I would also argue that it does not really improve the readability of the code.
However, the two subclasses of BooleanExecutionCondition both declare private final String annotationName fields.
Thus, if you change the annotationName field you have introduced to protected and modify AbstractJreCondition and AbstractJreRangeCondition so that they no longer declare or set the annotationName field, I would reconsider accepting this PR.
| .orElseGet(this::enabledByDefault); | ||
| } | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not modify lines of code unrelated to your change, and please do not add or remove blank lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alright thank you, my apologies, it was unoticed
| String reason = "@%s is not present".formatted(this.annotationName); | ||
| return enabled(reason); | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please restore this blank line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I will do just that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
annotationType.getSimpleName() to improve performanceannotationType.getSimpleName() in a field in BooleanExecutionCondition
|
Micro "optimization" shifting the work from the method (maybe not called) to the constructor (always called). Let's not do it - keep it as-is. |
@sormuras, I think what I proposed in #4619 (review) is worth doing. |
|
I'd rather convert those fields into variables. Why keep/introduce an extra state for something that's only used locally in a single method? |
If we create a private field in in However, So, if we want to continue to store the simple name in fields, we should just store the simple name once in a protected field in the common superclass.
If we don't want to continue storing the simple name in fields in any of the affected classes in that hierarchy, yes, we could calculate the simple name based on I'm also OK with going with that approach. @marcphilipp and @sormuras, WDYT? |
I'd prefer that approach. 👍 |
|
Team decision: @sbrannen himself will change the code according to his proposal in #4619 (comment). |
This commit removes the annotationName fields from AbstractJreCondition and AbstractJreRangeCondition and replaces them with local variables. See #4619
|
@Adagedo, thanks again for the PR, even though we decided to address this differently.
Done in 483fcc9. |
+1 👍 |
|
@sbrannen My pleasure |
Overview
My PR optimizes the performance and readability of the BooleanExecutionCondition class by memoizing the annotationType.SimpleName method.
I did not alter any logic though. I only introduced a lightweight internal optimization .
I hereby agree to the terms of the JUnit Contributor License Agreement.
Definition of Done
@APIannotations