fix: optimize glob pattern expansion to avoid full recursive directory traversal#501
fix: optimize glob pattern expansion to avoid full recursive directory traversal#501
Conversation
Summary of ChangesHello, 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 significantly improves the performance of glob pattern expansion within the configuration loading process. Previously, the system would unnecessarily traverse all directories, including large Highlights
Changelog
Activity
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.
Code Review
This pull request effectively addresses a performance issue with glob pattern expansion by replacing a manual recursive directory walk with the more efficient doublestar.GlobWalk. However, the new implementation removes the symlink cycle detection that was present in the original code, which could lead to infinite recursion and Denial of Service when processing malicious or misconfigured directory structures. Additionally, there is a minor deviation from the io/fs.ReadDirFile interface contract in the new vfsAdapter.
…y traversal Replace hand-rolled walkProjectFiles with doublestar.GlobWalk, which natively understands glob semantics (* = one level, ** = recursive) and only traverses directories as deep as the pattern requires. Introduce a vfs.FS → fs.FS adapter (vfsAdapter) so doublestar.GlobWalk can operate on the custom VFS interface. The adapter includes symlink cycle detection via realpath comparison in ReadDir to prevent infinite recursion when symlinks create directory cycles.
88c6d82 to
ab3ecdf
Compare
Summary
PR #493 introduced glob pattern support for
parserOptions.projectinrslint.json. However, thewalkProjectFilesimplementation recursively traversed all directories (includingnode_modules) regardless of the glob pattern's actual depth requirement. For a pattern like./packages/*/tsconfig.json, this caused ~4,000 unnecessary directory accesses instead of only checking the 8 direct children ofpackages/.This PR replaces the hand-rolled recursive walk with
doublestar.GlobWalk, which natively understands glob semantics (*= one level,**= recursive) and only traverses directories as deep as the pattern requires. Avfs.FS→fs.FSadapter (vfsAdapter) is introduced so thatdoublestar.GlobWalkcan operate on the custom VFS interface used throughout the project.The adapter also includes symlink cycle detection via realpath comparison in
ReadDir, preventing infinite recursion when symlinks create directory cycles (e.g.,packages/ui/loop -> packages).Before (v0.2.2): linted 242 files in 1.56s
After: linted 242 files in 448ms (~3.5x faster on this repo; larger monorepos with deeper
node_moduleswill see even greater improvement)Test Coverage
*,**,?,[0-9],[!a]*not matching nested dirsOpen(root/directory/file/not-exist),ReadDir(all/paginated/exhausted),DirEntrymetadataRelated Links
Checklist