Skip to content

perf(pluginutils): compile createFilter patterns once - #2026

Open
Cherry wants to merge 1 commit into
rollup:masterfrom
Cherry:perf/pluginutils-createfilter-compile-once
Open

Cherry wants to merge 1 commit into
rollup:masterfrom
Cherry:perf/pluginutils-createfilter-compile-once

Conversation

@Cherry

@Cherry Cherry commented Sep 28, 2026

Copy link
Copy Markdown

The matcher returned by getMatcher rebuilt the glob string and compiled a new picomatch matcher inside every test() call. Compile it once when the filter is created instead, and add a test that the number of picomatch compilations does not grow with the number of filter calls.

Rollup Plugin Name: pluginutils

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.

List any relevant issue numbers:

Picks up similar work in #1921, which was closed as abandoned.

Description

Discovered this minor improvement while benchmarking a larger project internally.

createFilter's string matchers rebuilt the glob and compiled a new picomatch matcher inside every test() call, so every filtered id paid the full compile cost for every pattern. This compiles each pattern once when the filter is created.

With a realistic include/exclude pair (src/**/*.ts, src/**/*.vue / src/storybook/**/*, src/**/*.stories.ts) over ~670 real paths, a filter call went from ~22.6碌s to ~1.1碌s, with identical results for every path.

@Cherry
Cherry requested a review from shellscape as a code owner September 28, 2026 02:17
@greptile-apps

greptile-apps Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Optimizes pattern matching in the filter utility.

The PR appears safe to merge; no outstanding or new actionable findings remain.

Reviews (2) 路 Last reviewed commit: "perf(pluginutils): compile createFilter ..."

Comment thread packages/pluginutils/src/createFilter.ts
The matcher returned by getMatcher rebuilt the glob string and compiled a new picomatch matcher
inside every test() call. Compile it when the filter is created and only recompile if the working
directory has changed since, so relative patterns still resolve against the cwd at call time.
@Cherry
Cherry force-pushed the perf/pluginutils-createfilter-compile-once branch from 80c18bc to fdaa3f1 Compare September 28, 2026 02:26
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