-
Notifications
You must be signed in to change notification settings - Fork 2.4k
performance optimization in visiting models #4911
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
performance optimization in visiting models #4911
Conversation
The `_field` attribute is not needed in Statement because it should only contain child nodes, but `type` and `tokens` are'nt child nodes. I move the value to the _attributes because then they can be dumped.
… ModelTransformer The original generic_visit method checks if the `_field` values are of type ast.AST and then if the values are if type list. because the `isinstance` check is releativ slow in python and because the RF Model is correctly defined and always returns `Node` or `List[Nodes]` we only need to check if the field is of type `List`
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 in general. Things to be done:
- The
_fields
->_attributes
change needs to be still investigated in a bit more detail. - Cache creation can be enhanced.
- Probably updating the cache can be streamlined as well.
I investigated the import ast
import astpretty
from robot.parsing import get_model
kw = get_model('''\
*** Test Cases ***
Example
Log Hello, world!
''').sections[0].body[0].body[0]
print('[ast.dump]')
print(ast.dump(kw))
print()
print('[ast.dump w/ attributes]')
print(ast.dump(kw, include_attributes=True))
print()
print('[astpretty]')
astpretty.pprint(kw) When I run the above code with the current code, I get this:
As you can see, When the current
As you can see, plain Based on this, I believe the change is fine. The The change can obviously cause issues if someone is inspecting |
the new generic_visitor methods needs this change, so when then this should be done before integrating this PR |
Now: before optimization
after optimization
|
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.
Changes to generic_visit
look pretty complicated. I think it would be better to concentrate on listener method cache first.
You can ignore comments related to the code style if you want. I can fine-tune the code after merging.
yes, you can commit an push and I will rebase this PR. But probably not before tomorrow. |
…handle generic_visit in VisitorFinder, but be safe from Liskov substitution principle
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.
This PR is getting too complicated. As I wrote in a separate comment, I believe this PR should concentrate on visitor method caching and everything else left out. Caching is relatively simple, but the custom generic_visit
implementation looks complicated and somewhat risky. I'd like to have simple stuff in first. After that more complicated changes are fine if they bring additional significant performance benefits.
I'm also not that happy with the added typing because it makes the code pretty complicated. The main reason is that the syntax for typing callables in Python is pretty horrible. I also don't see any real need for making the class generic (which requites TypeVar). This isn't a public API and trying to type it fully is a no-goal. Could be done if types don't get in the way, but in this case they do.
Due to the budget situation with RF 7.0, I won't have much time to spend for this. If you consider the changes that I oppose important, it might be better that the code lives outside Robot core.
This reverts commit bf5b3a2.
The latest version looked good. I'll take another locally and may make some fine-tuning. I'll also add a note about the cache to ModelVisitor docstring. |
Now that this PR is in and will be part of RF 7.0 alpha 1, a separate PR can be submitted about enhancing |
as discussed in slack, here are some performance optimizations for the ModelVisitor and ModelTransformer.
I will make several commits, one for each improvement.
My local tests promise a speed increase of about factor 4.
This improvement has not necessarily influence on execution speed of Robot but all tools which use the ModelVisitor or the ModelTransformer, like RobotCode, robocop or tidy.