Skip to content

perf: do not check every CLI path for each directory of a file path - #1482

Merged
dsherret merged 1 commit into
mainfrom
perf/literal-args
Nov 29, 2026
Merged

dsherret merged 1 commit into
mainfrom
perf/literal-args

Conversation

@dsherret

Copy link
Copy Markdown
Member

When providing many file paths on the command line (ex. --staged or an expanded shell glob), each directory above each file was checked against every provided path, which made the cost quadratic.

The directories of the non-glob patterns are now in a hash set, so only the actual globs get checked one by one. The result is the same as before, which a test verifies by comparing it with GlobPattern::matches_dir_for_traversal on each pattern.

dprint check with 500 file paths:

Before After
Windows 55.4ms 28.7ms
Linux 50.2ms 9.0ms
macOS 48.6ms 19.9ms

@dsherret
dsherret merged commit fc2d5a0 into main Nov 29, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant