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

Too many directories are scanned with multi-patterns #77

Closed
fabianwohlfart opened this issue Dec 3, 2024 · 7 comments
Closed

Too many directories are scanned with multi-patterns #77

fabianwohlfart opened this issue Dec 3, 2024 · 7 comments
Labels
duplicate This issue or pull request already exists

Comments

@fabianwohlfart
Copy link

If I have two patterns like this

const files = await glob(['../app/**/*.vue', '../utilities/**/*.vue'])

and a folder structure like this

- app
- should-not-matter
- utilities

not only the app and utilities folder are searched, but also the should-not-matter folder.
This leads to huge performance breakdowns, if not only one, but many folders are »in between«.

I came to this behavior through a weird warning in Nuxt, where suddenly my build process increased from 500ms to 25seconds.
nuxt/nuxt#30137

I tracked it down to a scanDirectory function in unimport, that took longer than expected
unjs/unimport#401

I came to the conclusion that they recently switched from glob to tinyglobby
Yet glob only takes a few milliseconds, but tinyglobby takes seconds to scan everything.

Here is a reproduction.
https://github.com/fabianwohlfart/test__nuxt-layers-slowdown

You can simply go to the app folder and run the tinyglobby.mjs, you will see that it searches the folder should-not-matter, which it shouldn't.

@fabianwohlfart fabianwohlfart changed the title Too many directories are searched Too many directories are scanned with multi-patterns Dec 3, 2024
@fabianwohlfart
Copy link
Author

What I cannot get my head around is:

With this pattern:
/Users/Development/Foundation/media/utils/*.{mts,cts,ts,tsx,mjs,cjs,js,jsx}

And this cwd:
/Users/Development/Project/website__bszb

The result of normalizePattern is:
../../Foundation/media/utils/*.{mts,cts,ts,tsx,mjs,cjs,js,jsx}/**

And it will search our complete potentialRoot
/Users/Development
(Which may holds soooo much content)

But why are we not directly searching this as a root?
/Users/Development/Foundation/media/utils

@SuperchupuDev
Copy link
Owner

SuperchupuDev commented Dec 3, 2024

already fixed in main by #69 (and is being improved in #76), you can test the latest commit by adding

  "overrides": {
    "tinyglobby": "https://pkg.pr.new/tinyglobby@d51e2b9"
  }

to your package.json. let me know if it works and i'll reopen this if it doesn't :)

@SuperchupuDev SuperchupuDev closed this as not planned Won't fix, can't repro, duplicate, stale Dec 3, 2024
@SuperchupuDev SuperchupuDev added the duplicate This issue or pull request already exists label Dec 3, 2024
@SuperchupuDev
Copy link
Owner

SuperchupuDev commented Dec 3, 2024

What I cannot get my head around is:

With this pattern: /Users/Development/Foundation/media/utils/*.{mts,cts,ts,tsx,mjs,cjs,js,jsx}

And this cwd: /Users/Development/Project/website__bszb

The result of normalizePattern is: ../../Foundation/media/utils/*.{mts,cts,ts,tsx,mjs,cjs,js,jsx}/**

And it will search our complete potentialRoot /Users/Development (Which may holds soooo much content)

But why are we not directly searching this as a root? /Users/Development/Foundation/media/utils

the old root optimizer didn't run if the pattern started with .., broke some tests. shouldn't be a problem ever since #69 got merged though (although there's yet to be a release that includes the commit)

@fabianwohlfart
Copy link
Author

Runs smoothly! Thanks for your work!

@fabianwohlfart
Copy link
Author

fabianwohlfart commented Dec 4, 2024

EDIT:
Ignore all the following. I made a mistake with the naming of my folders. All works. _ANOTHER does not exist; I renamed it recently to _Another.

(Leaving the comment for completeness)

Somehow this options

{ absolute: true,                                                                                                                                                                                         22:47:01
  cwd: '/Users/xyz/__Development/Client/website__client-v2',
  onlyFiles: true,
  followSymbolicLinks: true,
  patterns:
   [ '/Users/xyz/__Development/Client/website__client-v2/server/utils/*.{mts,cts,ts,tsx,mjs,cjs,js,jsx}',
     '/Users/xyz/__Development/_ANOTHER/another__foundation/content/server/utils/*.{mts,cts,ts,tsx,mjs,cjs,js,jsx}',
     '/Users/xyz/__Development/_ANOTHER/another__foundation/media/server/utils/*.{mts,cts,ts,tsx,mjs,cjs,js,jsx}',
     '/Users/xyz/__Development/_ANOTHER/another__foundation/website/server/utils/*.{mts,cts,ts,tsx,mjs,cjs,js,jsx}',
     '/Users/xyz/__Development/_ANOTHER/another__foundation/utilities/server/utils/*.{mts,cts,ts,tsx,mjs,cjs,js,jsx}' ] }

Will skip the _ANOTHER folder:

[tinyglobby 22:47:01] crawling /Users/xyz/__Development/Client/
[tinyglobby 22:47:01] skipped /Users/xyz/__Development/ProjectA/
[tinyglobby 22:47:01] skipped /Users/xyz/__Development/ProjectB/
[tinyglobby 22:47:01] skipped /Users/xyz/__Development/ProjectC/                                                                                                                             
[tinyglobby 22:47:01] skipped /Users/xyz/__Development/_Another/   

Due to exclude() most likely

@SuperchupuDev
Copy link
Owner

@fabianwohlfart FYI the newest release 0.2.11 should fix these problems. Can you test with that version?

@fabianwohlfart
Copy link
Author

yes works nuxt/nuxt#30137 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants