improve glob performance by not ignoring negate#2107
improve glob performance by not ignoring negate#2107Ugzuzg wants to merge 1 commit intoactions:mainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR improves glob performance by modifying the partialMatch function to respect negate patterns when determining whether to descend into directories. The change prevents the globber from traversing deep directory structures that would be filtered out by negate patterns anyway, significantly reducing glob operation time from over 1 minute to 250ms in the described scenario.
- Modified the
partialMatchfunction to check for negated patterns that match the current path - Updated corresponding test to reflect the new behavior where negated paths are not traversed
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/glob/src/internal-pattern-helper.ts | Enhanced partialMatch function to avoid descending into directories matched by negate patterns |
| packages/glob/tests/internal-pattern-helper.test.ts | Updated test case to verify the new negate pattern behavior |
| return ( | ||
| patterns.some(x => !x.negate && x.partialMatch(itemPath)) && | ||
| !patterns.some(x => x.negate && x.match(itemPath)) | ||
| ) |
There was a problem hiding this comment.
[nitpick] Consider short-circuiting the evaluation by checking negate patterns first, since if any negate pattern matches, the result will be false regardless of positive patterns. This could be written as: if (patterns.some(x => x.negate && x.match(itemPath))) return false; return patterns.some(x => !x.negate && x.partialMatch(itemPath));
| return ( | |
| patterns.some(x => !x.negate && x.partialMatch(itemPath)) && | |
| !patterns.some(x => x.negate && x.match(itemPath)) | |
| ) | |
| // Check negate patterns first for short-circuiting | |
| if (patterns.some(x => x.negate && x.match(itemPath))) { | |
| return false; | |
| } | |
| // Check positive patterns | |
| return patterns.some(x => !x.negate && x.partialMatch(itemPath)); |
Fixes #657
In a pnpm monorepo, I have the following patterns to upload with
upload-artifact:However, because a deep
apps/app-a/node_modules/abcis a partial match, the globber goes through files in a directory that will be filtered out later anyway.This reduces the time to find all matches from 1m 8s to 250ms with identical result arrays.