-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[Core] Optimize MethodScanner #1238
Conversation
…l cucumber annotations
javaBackend.addStepDefinition(annotation, method); | ||
} | ||
Annotation[] methodAnnotations = method.getAnnotations(); | ||
for (Annotation annotation : methodAnnotations) { |
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.
Might be even more efficient to use Method.getAnnotation(Class annotationClass) rather then checking all annotations. Then we can replace this for loop with two null checks.
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.
I'm not sure about it. Could you clarify? Based on previous logic one method can be annotated with Before/After and any number of step annotations - we can't achieve it without loop. Second thing is that we are not able to get step annotation e.g. @Given
using Method.getAnnotation(Class annotationClass)
because we don't know what annotation is used (actually cucumber does not care if it is @Given
or @Then
it just should be annotation that itself is annotated with @StepDefAnnotation
), eventually this code won't work: method.getAnnotation(StepDefAnnotation.class)
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.
Derp. You are correct. I didn't have the hierarchy of annotations properly in my mind.
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.
Looks good.
This does include a subtle change. Rather then accepting only annotations from cucumber.api
we now accept any annotation that implements
StepDefAnnotation
with a value and timeout method. Not something third parties should come to rely on. I don't think this will break anything.
Hi @lsuski, Thanks for your making your first contribution to Cucumber, and welcome to the Cucumber committers team! You can now push directly to this repo and all other repos under the cucumber organization! 🍾 In return for this generous offer we hope you will:
On behalf of the Cucumber core team, |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Optimized MethodScanner.scan method to not unnecessarily check for all cucumber annotations
Details
MethodScanner scans each method for existence of cucumber annotation (there are many). It is redundant and slow because only methods with Before/After or StepDefAnnotation are added to backend.
Motivation and Context
On Android < 7.0 it is extremely slow, and starting with debugger is almost impossible. I've measured it and optimized method is about 150 times faster on Android <7.0 and about 10 times faster on Android >=7.0
How Has This Been Tested?
MethodScannerTest passes.
I've also tested it on my Android project and it works (and it is much more faster)
Types of changes