-
-
Notifications
You must be signed in to change notification settings - Fork 269
fix: find_ending_with too slow #187
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
base: main
Are you sure you want to change the base?
Conversation
Find all qualified names ending with the given suffix using DFS on the trie.
This avoids a full scan of the `_entries` dict and instead walks the trie
structure once, checking each stored qualified name.
Summary of ChangesHello @AloneFire, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a performance bottleneck in the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request aims to optimize the find_ending_with method by replacing a full scan of the _entries dictionary with a DFS traversal on the trie. While the change is functionally correct, the new implementation duplicates logic that already exists in the find_with_prefix_and_suffix method. My review includes a suggestion to refactor the new method to reuse the existing one, which will improve code maintainability by removing redundancy.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
Thanks for the PR! The refactor to reuse However, I think the performance reasoning in the description is slightly off. Tries are optimized for prefix lookups, so searching for a suffix still requires visiting every node in the tree. There's no pruning possible when the prefix is empty. Actually, the new implementation is likely slower in practice. The DFS traverses every trie node (intermediate modules plus leaves) rather than just the qualified names in |
|
One more question: what would deprecating |
You're right, I didn't think through the implementation carefully. However, DFS did show significant speed improvements on my project. I've pushed a new commit that optimizes this using a different approach—trading space for time through indexing. |
vitali87
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.
1. Trailing Whitespace
Line 83 has trailing whitespace. Please install pre-commit hooks:
pre-commit installThis runs automatically on every commit and catches formatting issues.
2. No Benchmark Data
I previously asked about performance reasoning. Please provide before/after benchmark results.
3. Insufficient Test Coverage
Add tests for:
- Multi-part suffix:
find_ending_with("Logger.info") - Suffix index cleanup after deletion
- Multiple entries with same suffix
4. Coding Standards
Review CONTRIBUTING.md for project coding standards.
Please address all of these and re-request review. Thanks!
find_ending_with Find all qualified names ending with the given suffix using DFS on the trie.
This avoids a full scan of the
_entriesdict and instead walks the trie structure once, checking each stored qualified name.