Skip to content
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

Improve the performance when checking broad glob patterns. #14481

Merged
merged 3 commits into from
Sep 23, 2024

Conversation

ivanwonder
Copy link

In a large project, it's costly to repeatedly call the
function micromatch.isMatch that parses a glob pattern,
creates a regular expression, and tests the path name
against the regular expression. To optimize performance,
it's important to cache the parsing and creating process
before entering the loop.

For example, the content configuration in a project
looks like this
['./pages/**/*.{ts,js}', './node_modules/pages/**/*.{ts,js}'].
If the project has 10000 matched files and 10 glob patterns,
the function micromatch.isMatch will be called 100000 times.

Fixes #14353

In a large project, it's costly to repeatedly call the
function `micromatch.isMatch` that parses a glob pattern,
creates a regular expression, and tests the path name
against the regular expression. To optimize performance,
it's important to cache the parsing and creating process
before entering the loop.

For example, the content configuration in a project
looks like this
`['./pages/**/*.{ts,js}', './node_modules/pages/**/*.{ts,js}']`.
If the project has 10000 matched files and 10 glob patterns,
the function `micromatch.isMatch` will be called 100000 times.

Fixes tailwindlabs#14353
@ivanwonder
Copy link
Author

@RobinMalfait RobinMalfait merged commit 066ccf8 into tailwindlabs:main Sep 23, 2024
13 checks passed
@RobinMalfait
Copy link
Member

Hey! Thank you very much for this performance improvement! 💪

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.

2 participants