GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fs: cache glob matcher functions in path.matchesGlob by beeequeue · Pull Request #63915 · nodejs/node

Conversation

@beeequeue

@beeequeue beeequeue commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

this PR adds benchmarks for path.matchesGlob() as well as a simple cache for pattern matching functions.

rationale

most glob matching libraries in the ecosystem (including minimatch) provide an API to let users re-use matchers instead of re-creating them every call.

node doesn't provide such an API, and does not re-use matchers when possible, leading to it being much slower (10-15x) than just using new Minimatch() directly when matching a pattern more than once.

implementation details

i decided to "hide" away the cache inside the function rather than add a new API as most users will expect the function to not be a potential footgun, and the pattern has been used before in zeptomatch

since matchGlobPattern() doesn't accept any options other than pattern and path we can safely cache it by the pattern string. if this changes in the future the cache would need to accomodate the new options in the cache keys.

i went with the simplest Map cache implementation i could come up with as i couldn't find any LRU implementations anywhere in the codebase, if you have any suggestions for improvements please let me know!

testing

i'm not sure how to test this properly, e.g. if i should export the cache instance and check its size, etc

some guidance here is very appreciated :)


benchmark results

ran on my windows 11 machine with an AMD Ryzen 9800X3D

note: these benchmarks do not test the case where we evict keys from the cache

                                                                                                                confidence improvement accuracy (*)    (**)   (***)
path\matchesGlob-posix.js n=100000 pattern='src/**/baz/*.test.ts' path='src/foo/bar/biz/baz/index.test.ts'             ***   1013.11 %      ±23.55% ±31.74% ±42.14%
path\matchesGlob-posix.js n=100000 pattern='src/**/baz/*.test.ts' path='src/index.test.ts'                             ***   2005.02 %      ±48.08% ±64.80% ±86.02%
path\matchesGlob-posix.js n=100000 pattern='src/**/baz/*.test.ts' path='src/index.ts'                                  ***   2073.47 %      ±27.53% ±37.10% ±49.24%
path\matchesGlob-posix.js n=100000 pattern='src/**/baz/*.ts' path='src/foo/bar/biz/baz/index.test.ts'                  ***    869.89 %      ±18.72% ±25.22% ±33.48%
path\matchesGlob-posix.js n=100000 pattern='src/**/baz/*.ts' path='src/index.test.ts'                                  ***   1726.85 %      ±29.66% ±39.97% ±53.07%
path\matchesGlob-posix.js n=100000 pattern='src/**/baz/*.ts' path='src/index.ts'                                       ***   1777.43 %      ±25.94% ±34.95% ±46.40%
path\matchesGlob-posix.js n=100000 pattern='test/**/*.ts' path='src/foo/bar/biz/baz/index.test.ts'                     ***   1074.40 %      ±22.04% ±29.70% ±39.43%
path\matchesGlob-posix.js n=100000 pattern='test/**/*.ts' path='src/index.test.ts'                                     ***   1424.64 %      ±28.72% ±38.70% ±51.38%
path\matchesGlob-posix.js n=100000 pattern='test/**/*.ts' path='src/index.ts'                                          ***   1460.18 %      ±17.52% ±23.60% ±31.33%
path\matchesGlob-win32.js n=100000 pattern='src/**/baz/*.test.ts' path='src/foo/bar/biz/baz/index.test.ts'             ***    659.77 %       ±7.00%  ±9.43% ±12.52%
path\matchesGlob-win32.js n=100000 pattern='src/**/baz/*.test.ts' path='src/index.ts'                                  ***   1056.32 %      ±12.77% ±17.21% ±22.84%
path\matchesGlob-win32.js n=100000 pattern='src/**/baz/*.test.ts' path='src\\foo\\bar\\biz\\baz\\index.test.ts'        ***    492.15 %       ±4.26%  ±5.73%  ±7.60%
path\matchesGlob-win32.js n=100000 pattern='src/**/baz/*.test.ts' path='src\\index.ts'                                 ***    858.27 %       ±6.41%  ±8.64% ±11.46%
path\matchesGlob-win32.js n=100000 pattern='src/**/baz/*.ts' path='src/foo/bar/biz/baz/index.test.ts'                  ***    565.03 %       ±5.60%  ±7.54% ±10.01%
path\matchesGlob-win32.js n=100000 pattern='src/**/baz/*.ts' path='src/index.ts'                                       ***    915.51 %       ±9.18% ±12.38% ±16.42%
path\matchesGlob-win32.js n=100000 pattern='src/**/baz/*.ts' path='src\\foo\\bar\\biz\\baz\\index.test.ts'             ***    431.51 %       ±3.11%  ±4.18%  ±5.51%
path\matchesGlob-win32.js n=100000 pattern='src/**/baz/*.ts' path='src\\index.ts'                                      ***    746.71 %       ±6.50%  ±8.75% ±11.62%
path\matchesGlob-win32.js n=100000 pattern='test/**/*.ts' path='src/foo/bar/biz/baz/index.test.ts'                     ***    597.13 %      ±12.85% ±17.31% ±22.97%
path\matchesGlob-win32.js n=100000 pattern='test/**/*.ts' path='src/index.ts'                                          ***    745.44 %      ±12.25% ±16.50% ±21.90%
path\matchesGlob-win32.js n=100000 pattern='test/**/*.ts' path='src\\foo\\bar\\biz\\baz\\index.test.ts'                ***    421.16 %       ±3.44%  ±4.61%  ±6.08%
path\matchesGlob-win32.js n=100000 pattern='test/**/*.ts' path='src\\index.ts'                                         ***    594.88 %      ±10.85% ±14.62% ±19.41%

i also have a personal benchmarking repo where i found this issue, where the results now look like this:

screenshot image

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

fabiospampinato and Stanzilla reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
@nodejs-github-bot

nodejs-github-bot commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/performance
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot nodejs-github-bot added fs Issues and PRs related to file-system APIs and the fs module. needs-ci PRs that need a full CI run. labels Jun 14, 2026
beeequeue
beeequeue commented Jun 14, 2026
View reviewed changes
Comment thread lib/internal/fs/glob.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread lib/internal/fs/glob.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread lib/internal/fs/glob.js
if (patternFnCache.has(pattern)) {
matcher = patternFnCache.get(pattern);
} else {
matcher = createMatcher(pattern, {

@beeequeue beeequeue Jun 14, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i re-used createMatcher from above as i saw that it uses the same default options as the previous lines did.

i thought about putting the caching in that function instead, but then we would need to base the caching on all the options it accepts, so i decided to keep it here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@beeequeue
path: add benchmarks for path.matchesGlob()
137b97c
Signed-off-by: Adam Haglund <[email protected]>
@beeequeue
beeequeue force-pushed the matchesGlob-perf branch from 83d6da0 to d158f29 Compare June 30, 2026 08:32
@beeequeue

beeequeue commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

@avivkeller @MoLow if you have time, could you take a look at this PR? 🥰

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@beeequeue
fs: add pattern cache for matchGlobPattern()
f87f628
Signed-off-by: Adam Haglund <[email protected]>
@beeequeue
beeequeue force-pushed the matchesGlob-perf branch from d158f29 to f87f628 Compare July 4, 2026 09:09
avivkeller
avivkeller approved these changes Jul 4, 2026
View reviewed changes
@beeequeue

beeequeue commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

@avivkeller is there anything i can do to help get this merged?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@avivkeller

avivkeller commented Jul 10, 2026

Copy link
Copy Markdown
Member

cc @nodejs/fs PTAL

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mcollina
mcollina approved these changes Jul 13, 2026
View reviewed changes

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Jul 13, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Jul 13, 2026
@nodejs-github-bot

nodejs-github-bot commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/74794/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@beeequeue

beeequeue commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

@mcollina should i do something about these failing checks? i don't have access to see the results and i'm unsure if any of the test failures i see on my machine are because of my changes

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot

nodejs-github-bot commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/74831/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot

nodejs-github-bot commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/74839/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mcollina mcollina added commit-queue PRs queued for automated landing through the Commit Queue. author ready PRs with CI started, the required approvals, and no outstanding review comments. and removed needs-ci PRs that need a full CI run. labels Jul 16, 2026
@nodejs-github-bot nodejs-github-bot added commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. and removed commit-queue PRs queued for automated landing through the Commit Queue. labels Jul 16, 2026
@nodejs-github-bot

nodejs-github-bot commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator
Commit Queue failed
- Loading data for nodejs/node/pull/63915
✔  Done loading data for nodejs/node/pull/63915
----------------------------------- PR info ------------------------------------
Title      fs: cache glob matcher functions in path.matchesGlob (#63915)
Author     Adam Haglund <[email protected]> (@beeequeue, first-time contributor)
Branch     beeequeue:matchesGlob-perf -> nodejs:main
Labels     fs, author ready
Commits    2
 - path: add benchmarks for path.matchesGlob()
 - fs: add pattern cache for matchGlobPattern()
Committers 1
 - bq <[email protected]>
PR-URL: https://github.com/nodejs/node/pull/63915
Reviewed-By: Aviv Keller <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/63915
Reviewed-By: Aviv Keller <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
--------------------------------------------------------------------------------
   ℹ  This PR was created on Sun, 14 Jun 2026 13:41:33 GMT
   ✔  Approvals: 2
   ✔  - Aviv Keller (@avivkeller): https://github.com/nodejs/node/pull/63915#pullrequestreview-4630220976
   ✔  - Matteo Collina (@mcollina) (TSC): https://github.com/nodejs/node/pull/63915#pullrequestreview-4688113820
   ✔  Last GitHub CI successful
   ℹ  Last Full PR CI on 2026-07-15T15:29:50Z: https://ci.nodejs.org/job/node-test-pull-request/74839/
- Querying data for job/node-test-pull-request/74839/
✔  Build data downloaded
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  No git cherry-pick in progress
   ✔  No git am in progress
   ✔  No git rebase in progress
--------------------------------------------------------------------------------
- Bringing origin/main up to date...
From https://github.com/nodejs/node
 * branch                  main       -> FETCH_HEAD
✔  origin/main is now up-to-date
- Downloading patch for 63915
From https://github.com/nodejs/node
 * branch                  refs/pull/63915/merge -> FETCH_HEAD
✔  Fetched commits as 874e96ee4cd0..f87f628b4e4b
--------------------------------------------------------------------------------
[main d9c89a650e] path: add benchmarks for path.matchesGlob()
 Author: bq <[email protected]>
 Date: Sun Jun 14 14:53:03 2026 +0200
 2 files changed, 57 insertions(+)
 create mode 100644 benchmark/path/matchesGlob-posix.js
 create mode 100644 benchmark/path/matchesGlob-win32.js
[main a3e8124ad7] fs: add pattern cache for matchGlobPattern()
 Author: bq <[email protected]>
 Date: Sat Jun 13 18:06:10 2026 +0200
 1 file changed, 20 insertions(+), 10 deletions(-)
   ✔  Patches applied
There are 2 commits in the PR. Attempting autorebase.
(node:395) [DEP0190] DeprecationWarning: Passing args to a child process with shell option true can lead to security vulnerabilities, as the arguments are not escaped, only concatenated.
(Use `node --trace-deprecation ...` to show where the warning was created)
Rebasing (2/4)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
path: add benchmarks for path.matchesGlob()

Signed-off-by: Adam Haglund <[email protected]>
PR-URL: #63915
Reviewed-By: Aviv Keller <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>

[detached HEAD 39c08b796c] path: add benchmarks for path.matchesGlob()
Author: bq <[email protected]>
Date: Sun Jun 14 14:53:03 2026 +0200
2 files changed, 57 insertions(+)
create mode 100644 benchmark/path/matchesGlob-posix.js
create mode 100644 benchmark/path/matchesGlob-win32.js
Rebasing (3/4)
Rebasing (4/4)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
fs: add pattern cache for matchGlobPattern()

Signed-off-by: Adam Haglund <[email protected]>
PR-URL: #63915
Reviewed-By: Aviv Keller <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>

[detached HEAD a1983d94de] fs: add pattern cache for matchGlobPattern()
Author: bq <[email protected]>
Date: Sat Jun 13 18:06:10 2026 +0200
1 file changed, 20 insertions(+), 10 deletions(-)
Successfully rebased and updated refs/heads/main.

ℹ Add commit-queue-squash label to land the PR as one commit, or commit-queue-rebase to land as separate commits.

https://github.com/nodejs/node/actions/runs/29491987867

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mcollina mcollina added commit-queue PRs queued for automated landing through the Commit Queue. commit-queue-squash PRs the Commit Queue should land as one squashed commit. commit-queue-rebase PRs the Commit Queue should land as multiple self-contained commits. and removed commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. commit-queue-squash PRs the Commit Queue should land as one squashed commit. labels Jul 17, 2026
@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Jul 17, 2026
@nodejs-github-bot

nodejs-github-bot commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Landed in 1d4e86e...b8f81e9

beeequeue reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

nodejs-github-bot pushed a commit that referenced this pull request Jul 17, 2026
@beeequeue @nodejs-github-bot
path: add benchmarks for path.matchesGlob()
0a32b56
Signed-off-by: Adam Haglund <[email protected]>
PR-URL: #63915
Reviewed-By: Aviv Keller <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
nodejs-github-bot pushed a commit that referenced this pull request Jul 17, 2026
@beeequeue @nodejs-github-bot
fs: add pattern cache for matchGlobPattern()
b8f81e9
Signed-off-by: Adam Haglund <[email protected]>
PR-URL: #63915
Reviewed-By: Aviv Keller <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
@nodejs-github-bot nodejs-github-bot closed this Jul 17, 2026
@beeequeue
beeequeue deleted the matchesGlob-perf branch July 18, 2026 07:57
@beeequeue
beeequeue restored the matchesGlob-perf branch July 18, 2026 07:57
aduh95 pushed a commit that referenced this pull request Jul 21, 2026
@beeequeue @aduh95
path: add benchmarks for path.matchesGlob()
ef6c7b2
Signed-off-by: Adam Haglund <[email protected]>
PR-URL: #63915
Reviewed-By: Aviv Keller <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
aduh95 pushed a commit that referenced this pull request Jul 21, 2026
@beeequeue @aduh95
fs: add pattern cache for matchGlobPattern()
d4f89c9
Signed-off-by: Adam Haglund <[email protected]>
PR-URL: #63915
Reviewed-By: Aviv Keller <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
@github-actions github-actions Bot mentioned this pull request Jul 21, 2026
2026-07-22, Version 26.6.0 (Current) #64655
Merged
aduh95 pushed a commit that referenced this pull request Jul 21, 2026
@beeequeue @aduh95
path: add benchmarks for path.matchesGlob()
6f272d8
Signed-off-by: Adam Haglund <[email protected]>
PR-URL: #63915
Reviewed-By: Aviv Keller <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
aduh95 pushed a commit that referenced this pull request Jul 21, 2026
@beeequeue @aduh95
fs: add pattern cache for matchGlobPattern()
64767b8
Signed-off-by: Adam Haglund <[email protected]>
PR-URL: #63915
Reviewed-By: Aviv Keller <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
aduh95 pushed a commit that referenced this pull request Jul 21, 2026
@beeequeue @aduh95
path: add benchmarks for path.matchesGlob()
9ac1b68
Signed-off-by: Adam Haglund <[email protected]>
PR-URL: #63915
Reviewed-By: Aviv Keller <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
aduh95 pushed a commit that referenced this pull request Jul 21, 2026
@beeequeue @aduh95
fs: add pattern cache for matchGlobPattern()
17face6
Signed-off-by: Adam Haglund <[email protected]>
PR-URL: #63915
Reviewed-By: Aviv Keller <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
@mag123c mag123c mentioned this pull request Jul 26, 2026
path: add exclude option to matchesGlob method #59061
Open
RafaelGSS pushed a commit that referenced this pull request Jul 29, 2026
@beeequeue @RafaelGSS
path: add benchmarks for path.matchesGlob()
5dd34d7
Signed-off-by: Adam Haglund <[email protected]>
PR-URL: #63915
Reviewed-By: Aviv Keller <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
RafaelGSS pushed a commit that referenced this pull request Jul 29, 2026
@beeequeue @RafaelGSS
fs: add pattern cache for matchGlobPattern()
4a3ef5b
Signed-off-by: Adam Haglund <[email protected]>
PR-URL: #63915
Reviewed-By: Aviv Keller <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
aduh95 pushed a commit that referenced this pull request Aug 6, 2026
@beeequeue @aduh95
path: add benchmarks for path.matchesGlob()
224d2c7
Signed-off-by: Adam Haglund <[email protected]>
PR-URL: #63915
Reviewed-By: Aviv Keller <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
aduh95 pushed a commit that referenced this pull request Aug 6, 2026
@beeequeue @aduh95
fs: add pattern cache for matchGlobPattern()
e5af022
Signed-off-by: Adam Haglund <[email protected]>
PR-URL: #63915
Reviewed-By: Aviv Keller <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
@github-actions github-actions Bot mentioned this pull request Aug 21, 2026
2026-08-26, Version 24.20.0 'Krypton' (LTS) #65461
Merged
@jeddy3 jeddy3 mentioned this pull request Sep 24, 2026
Change globbyOptions to support only a subset of options stylelint/stylelint#9500
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@mcollina mcollina mcollina approved these changes
@avivkeller avivkeller avivkeller approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. commit-queue-rebase PRs the Commit Queue should land as multiple self-contained commits. fs Issues and PRs related to file-system APIs and the fs module.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@beeequeue @nodejs-github-bot @avivkeller @mcollina
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.