Skip to content

perf: precompile picomatch matchers once per scan#535

Merged
antfu merged 1 commit into
mainfrom
perf/cache-scan-dir-matchers
May 14, 2026
Merged

perf: precompile picomatch matchers once per scan#535
antfu merged 1 commit into
mainfrom
perf/cache-scan-dir-matchers

Conversation

@danielroe

@danielroe danielroe commented May 9, 2026

Copy link
Copy Markdown
Member

spotted this as a perf improvement while investigating nuxt/nuxt#27106. - pm.isMatch(file, glob) rebuilds matchers on every call (ie compiles to regular expressions) which has a measurable cost

Summary by CodeRabbit

  • Refactor
    • Optimized directory scanning and file type filtering for improved performance.

@danielroe danielroe requested a review from antfu May 9, 2026 06:26
@danielroe danielroe self-assigned this May 9, 2026
@coderabbitai

coderabbitai Bot commented May 9, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR optimizes glob matching performance in scan-dirs.ts by pre-compiling picomatch matchers once and reusing them across multiple file and directory checks, eliminating redundant matcher instantiation.

Changes

Matcher Optimization

Layer / File(s) Summary
Matcher Pre-compilation
src/node/scan-dirs.ts
indexOfDirs and isIncludeTypes now pre-compile picomatch matchers from glob arrays and reuse the compiled functions, replacing per-call pm.isMatch invocations against raw glob strings.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

A rabbit hops through globs with glee,
Pre-compiled matchers, faster spree! ✨
No more repeating work in vain,
One match, one matcher, cleaner gain. 🐰

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'perf: precompile picomatch matchers once per scan' accurately and concisely describes the main change: pre-compiling matchers for performance optimization rather than rebuilding them on each call.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/cache-scan-dir-matchers

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@danielroe danielroe changed the title perf: precompile matchers once per scan perf: precompile picomatch matchers once per scan May 9, 2026
@antfu antfu merged commit 2890dfd into main May 14, 2026
4 checks passed
@antfu antfu deleted the perf/cache-scan-dir-matchers branch May 14, 2026 08:37
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