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

Refactor ASTNode.get_parent() to improve runtime performance #1049

Merged
merged 5 commits into from
May 21, 2024

Conversation

clinssen
Copy link
Contributor

@clinssen clinssen commented May 8, 2024

Add an ASTParentVisitor which sets an attribute parent_ on each ASTNode on the basis of calls to get_children() on ASTNodes, making the AST a doubly-linked tree. This is (probably) the fastest and easiest solution, but of course has the disadvantage that information is stored redundantly.

As a test for self-consistency, an assert is added to check that self is in parent_.get_children() in each call to get_parent().

Fixes #1024.

@clinssen clinssen marked this pull request as draft May 8, 2024 09:59
@clinssen clinssen requested a review from pnbabu May 15, 2024 22:00
@clinssen clinssen marked this pull request as ready for review May 15, 2024 22:00
@clinssen clinssen added this to the NESTML 8.0.0 milestone May 16, 2024
pynestml/meta_model/ast_declaration.py Show resolved Hide resolved
pynestml/meta_model/ast_expression.py Outdated Show resolved Hide resolved
pynestml/meta_model/ast_input_port.py Show resolved Hide resolved
@clinssen clinssen requested a review from pnbabu May 17, 2024 15:36
@clinssen
Copy link
Contributor Author

Thank you for the review, good catch! I have addressed all your comments in the latest commit.

Copy link
Contributor

@pnbabu pnbabu left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks!

@pnbabu pnbabu merged commit 076bd89 into nest:master May 21, 2024
8 checks passed
@clinssen
Copy link
Contributor Author

Thanks for the review!

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

Successfully merging this pull request may close these issues.

get_parent() is excruciatingly slow
2 participants