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

Rule: walk-no-path #1219

Merged
merged 1 commit into from
Oct 23, 2024
Merged

Rule: walk-no-path #1219

merged 1 commit into from
Oct 23, 2024

Conversation

anderseknert
Copy link
Member

Suggest replacing the path variable with a wildcard where possible, as the walk built-in is able to optimize such calls. More info in the docs included in the PR.

Also:

  • Add ast.is_wildcard convenience function and use it consistently

Fixes #1154

Copy link
Member

@charlieegan3 charlieegan3 left a comment

Choose a reason for hiding this comment

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

This is great! No comments from me on this one.

@charlieegan3
Copy link
Member

The only thing I wondered about was showing the results of some testing to motivate this rule, e.g. for a deeply nested walk of 1mb of json this can make the walk 50% faster or similar. It might be good for the other performance category rules too.

Suggest replacing the path variable with a wildcard where possible, as
the walk built-in is able to optimize such calls. More info in the docs
included in the PR.

Also:
- Add `ast.is_wildcard` convenience function and use it consistently

Fixes #1154

Signed-off-by: Anders Eknert <anders@styra.com>
@anderseknert
Copy link
Member Author

@charlieegan3 added!

More concretely, walking without generating the path array cuts down evaluation time by about 33%, and reduces the
number of allocations by about 40%.

@anderseknert anderseknert merged commit 0ce82ae into main Oct 23, 2024
4 checks passed
@anderseknert anderseknert deleted the walk-no-path branch October 23, 2024 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rule: walk-no-path
2 participants