Skip to content

Conversation

@AloneFire
Copy link

find_ending_with 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.

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.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 find_ending_with method within the graph_updater.py module. By replacing a linear scan of all entries with a more efficient Depth-First Search (DFS) traversal of the underlying trie structure, the method can now locate qualified names ending with a specific suffix much faster, significantly improving the overall efficiency of name lookups.

Highlights

  • Performance Improvement: The find_ending_with method in codebase_rag/graph_updater.py has been refactored to significantly improve its performance.
  • Algorithm Change: The method now utilizes a Depth-First Search (DFS) traversal on the trie structure instead of a full scan of the _entries dictionary, making suffix-based lookups much more efficient.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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>
@vitali87
Copy link
Owner

vitali87 commented Dec 8, 2025

Thanks for the PR! The refactor to reuse find_with_prefix_and_suffix is a nice cleanup.

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 _entries. On top of that, recursive Python function calls have significantly more overhead than iterating a flat dictionary, which uses CPython's optimized C implementation.

@vitali87
Copy link
Owner

vitali87 commented Dec 8, 2025

One more question: what would deprecating _entries actually give us? Is there a concrete memory or maintainability benefit you're aiming for?

@AloneFire
Copy link
Author

AloneFire commented Dec 9, 2025

One more question: what would deprecating _entries actually give us? Is there a concrete memory or maintainability benefit you're aiming for?

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.

Copy link
Owner

@vitali87 vitali87 left a 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 install

This 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!

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

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants