Skip to content

Avoid compiling ignore patterns twice#190

Merged
SuperchupuDev merged 1 commit intoSuperchupuDev:mainfrom
webpro:perf/compile-ignore-once
Feb 18, 2026
Merged

Avoid compiling ignore patterns twice#190
SuperchupuDev merged 1 commit intoSuperchupuDev:mainfrom
webpro:perf/compile-ignore-once

Conversation

@webpro
Copy link
Copy Markdown
Contributor

@webpro webpro commented Jan 30, 2026

The ignore patterns were compiled both via picomatch's ignore option and as a standalone matcher. This PR makes it compile once, and apply manually in filter only.

Coming from webpro-nl/knip#1462 (comment). The change in this PR would make globbing go from >700ms to <320ms in that particular setup, because there are lots of .gitignore files resulting in lots of ignore patterns passed in to tinyglobby#globSync

Here's a script to benchmark the difference:

import { globSync } from './dist/index.mjs';
const ignore = [
  '**/node_modules/**',
  '**/.git/**',
  '**/dist/**',
  '**/build/**',
  '**/coverage/**',
  ...Array.from({ length: 35 }, (_, i) => `**/ignored${i}/**`)
];
const patterns = ['**/*.ts', '**/*.js'];
const cwd = process.cwd();
globSync(patterns, { cwd, ignore }); // Warm up
const iterations = 500;
const start = performance.now();
for (let i = 0; i < iterations; i++) {
  globSync(patterns, { cwd, ignore, expandDirectories: false });
}
const elapsed = performance.now() - start;
console.log(`Total: ${elapsed.toFixed(0)}ms`);
console.log(`Avg: ${(elapsed / iterations).toFixed(2)}ms`);

This should show >40% improvement in time spent compared with main.

Let me know if you need anything else or how I can help with improve/benchmark this. Figured tests passing is enough for general QA?

The ignore patterns were compiled both via picomatch's ignore option
and as a standalone matcher. Compile once and apply manually in filter.
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Jan 30, 2026

Open in StackBlitz

npm i https://pkg.pr.new/tinyglobby@190

commit: 4e8031d

@webpro webpro marked this pull request as ready for review January 30, 2026 06:02
@SuperchupuDev
Copy link
Copy Markdown
Owner

i think i didn't do that initially because of some edge cases around the behavior of the negation of globstars? i'll test the pr soon (hopefully). but it's a good sign that the tests are passing 👍

@wojtekmaj
Copy link
Copy Markdown

@SuperchupuDev Is there anything I could help you with to land this sooner? I'm super excited for tinyglobby to get faster and consequently knip replacing fast-glob with it, shaving off 15 deps. If you could recall the edge cases, maybe I could write some extra tests for example?

@SuperchupuDev
Copy link
Copy Markdown
Owner

SuperchupuDev commented Feb 17, 2026

hi!! i've just finished some important university exams and have enough free time now to look at tinyglobby development, sorry for the wait. i'd say don't worry about it, i think i can test it myself in a day or two. the edge case i'm looking for isn't complicated i just can't remember right now exactly what it was

Copy link
Copy Markdown
Owner

@SuperchupuDev SuperchupuDev left a comment

Choose a reason for hiding this comment

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

okay i tested a bunch and couldn't find any pattern that produces a different result than 0.2.15, so i'm merging this. will probably test some more later just in case. thank you!!

@SuperchupuDev SuperchupuDev merged commit 2a40183 into SuperchupuDev:main Feb 18, 2026
8 checks passed
@webpro webpro deleted the perf/compile-ignore-once branch March 7, 2026 09:57
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.

3 participants