Skip to content

Conversation

@EricRahm
Copy link
Contributor

@EricRahm EricRahm commented Jan 8, 2026

Summary

This commit optimizes file filtering by caching compiled ignore instances within the GitIgnoreParser instead of raw string arrays.

Details

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.

Related Issues

Fixes #11610

How to Validate

  • Existing unit/integration tests cover this code
  • Run gemini-cli in a directory with a root .gitignore and nested .gitignore files

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@EricRahm EricRahm requested a review from a team as a code owner January 8, 2026 19:24
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 GitIgnoreParser by optimizing how .gitignore files are processed and cached. Instead of repeatedly parsing raw ignore patterns, the system now stores and reuses pre-compiled ignore objects, leading to more efficient file filtering, especially in projects with complex or deeply nested .gitignore structures. This change directly addresses and fixes issue #11610.

Highlights

  • Performance Optimization: Switched from caching raw .gitignore rule strings to caching compiled ignore instances from the node-ignore library, significantly reducing parsing overhead during file filtering.
  • Type System Update: Updated internal cache types from Map<string, string[]> to Map<string, Ignore> and globalPatterns from string[] to Ignore to reflect the new caching strategy.
  • GitIgnoreParser Refinement: Modified loadPatternsForFile to directly return Ignore instances and ensured empty Ignore instances are cached or returned when no patterns are found, streamlining the ignore logic.
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.

@gemini-cli gemini-cli bot added priority/p2 Important but can be addressed in a future release. area/core Issues related to User Interface, OS Support, Core Functionality area/performance labels Jan 8, 2026
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 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();
Copy link
Contributor

Choose a reason for hiding this comment

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

high

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.

Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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!

@Adib234 Adib234 self-requested a review January 8, 2026 19:57
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
@EricRahm EricRahm force-pushed the ignore/cache-ignore-instances branch from 767c4f8 to 2eaa99e Compare January 9, 2026 17:27
@Adib234 Adib234 added this pull request to the merge queue Jan 9, 2026
Merged via the queue into google-gemini:main with commit e04a5f0 Jan 9, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality priority/p2 Important but can be addressed in a future release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Performance: Cache ignore instances in GitIgnoreParser

2 participants