-
Notifications
You must be signed in to change notification settings - Fork 10.6k
feat(core): Cache ignore instances for performance #16185
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
feat(core): Cache ignore instances for performance #16185
Conversation
Summary of ChangesHello @EricRahm, 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 introduces a performance enhancement to 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 introduces a performance optimization by caching compiled ignore instances instead of raw string arrays in the GitIgnoreParser. The changes are logical and correctly implement the caching strategy for .gitignore files and global git exclude files. My review focuses on ensuring this optimization is applied consistently. I've identified one area where the optimization was missed, which could impact performance when extra ignore patterns are used. Overall, this is a valuable improvement.
| private projectRoot: string; | ||
| private cache: Map<string, string[]> = new Map(); | ||
| private globalPatterns: string[] | undefined; | ||
| private cache: Map<string, Ignore> = new Map(); |
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 change to cache Ignore instances is a great performance improvement. For consistency and to fully realize the performance gains, processedExtraPatterns should also be converted to an Ignore instance. Currently, it remains a string[] and its patterns are re-parsed on every isIgnored call, which partially undermines the goal of this optimization when extraPatterns are provided. I recommend changing processedExtraPatterns to be of type Ignore and initializing it once in the constructor.
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.
Can this comment be addressed?
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.
Yep, I'll push an updated PR.
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.
Updated! @gemini-code-assist please review again.
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.
Thanks for the update, EricRahm! I've reviewed the changes, and they successfully address the feedback regarding processedExtraPatterns. Converting it to an Ignore instance and initializing it in the constructor, along with simplifying its usage in isIgnored, fully realizes the performance gains as intended. Great work!
This commit optimizes file filtering by caching compiled `ignore` instances within the `GitIgnoreParser` instead of raw string arrays. Previously, `.gitignore` files were parsed into an array of rule strings on every check, leading to redundant processing. The `node-ignore` library supports adding pre-compiled `ignore` instances, which is more efficient. This change modifies the internal cache from `Map<string, string[]>` to `Map<string, Ignore>` and updates the logic in `isIgnored` to create, cache, and reuse these compiled instances. This reduces the overhead associated with parsing ignore files, especially in large projects with many nested `.gitignore` files. Fixes google-gemini#11610
767c4f8 to
2eaa99e
Compare
Summary
This commit optimizes file filtering by caching compiled
ignoreinstances within theGitIgnoreParserinstead of raw string arrays.Details
Previously,
.gitignorefiles were parsed into an array of rule strings on every check, leading to redundant processing. Thenode-ignorelibrary supports adding pre-compiledignoreinstances, which is more efficient.This change modifies the internal cache from
Map<string, string[]>toMap<string, Ignore>and updates the logic inisIgnoredto create, cache, and reuse these compiled instances. This reduces the overhead associated with parsing ignore files, especially in large projects with many nested.gitignorefiles.Related Issues
Fixes #11610
How to Validate
.gitignoreand nested.gitignorefilesPre-Merge Checklist