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

[bug] Moon commands hang when a repo has multiple projects with node_modules dir #1721

Open
dudicoco opened this issue Nov 15, 2024 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@dudicoco
Copy link

dudicoco commented Nov 15, 2024

Describe the bug

In a repo with multiple projects and node_modules dir per project, moon commands become very slow.
It seems that moon checks the contents of each node_modules dir each time.

Steps to reproduce

  1. clone https://github.com/dudicoco/moon-reproduction
  2. run moon :install
    • the command completes immediately
  3. run pnpm install
  4. run moon :install
    • the command hangs for a few seconds

Environment

$ moon --version    
moon 1.29.4
@dudicoco dudicoco added the bug Something isn't working label Nov 15, 2024
@milesj
Copy link
Collaborator

milesj commented Nov 27, 2024

It looks like the slowdown is the glob. There's nothing about node_modules in the logs.

[DEBUG 15:16:58.563] moon_project_graph::project_graph_builder  Locating projects with globs  globs=["apps/*/*"]
[DEBUG 15:17:08.247] moon_project_graph::project_graph_builder  Attempting to load apps/backend/app-01/moon.yml (optional)  id="app-01"

If we change it to apps/backend/*, the perf issues go away:

[DEBUG 15:18:49.164] moon_project_graph::project_graph_builder  Locating projects with globs  globs=["apps/backend/*"]
[DEBUG 15:18:58.732] moon_project_graph::project_graph_builder  Attempting to load apps/backend/app-01/moon.yml (optional)  id="app-01"

We use a 3rd party globbing library, so we don't have much control here.

@dudicoco
Copy link
Author

@milesj since this basically makes moon unusable with larger repos what could be done here?
Should we open an issue upstream?

@milesj
Copy link
Collaborator

milesj commented Nov 29, 2024

Looks like there's a probably relevant thread here: olson-sean-k/wax#51

@dudicoco
Copy link
Author

@milesj I am not sure this is a performance issue but rather a configuration/misconfiguration issue in either moon, wax or walkdir.

There are three problems here:

  1. The glob is for apps/*/*, node_modules are in apps/*/*/node_modules. So the glob is continuing walking the dirs. Is there a min/max depth option?
  2. Since files here are irrelevant, the glob should only search for directories.
  3. The glob is not respecting .gitignore, if it did then node_modules wouldn't have an impact.

Here's an illustration:

$ time find apps/*/*
find apps/*/*  0.98s user 23.13s system 45% cpu 52.589 total

$ find apps/*/* -type d
find apps/*/* -type d  0.80s user 21.56s system 47% cpu 46.765 total

$time find apps/*/* -maxdepth 1
find apps/*/* -maxdepth 1  0.00s user 0.01s system 36% cpu 0.043 total

# emulating what respect .gitignore would do
$ time find apps/*/* -prune -o -name 'node_modules'
find apps/*/* -prune -o -name 'node_modules'  0.00s user 0.00s system 60% cpu 0.006 total

@milesj
Copy link
Collaborator

milesj commented Dec 1, 2024

So node_modules is already a globally negated glob: https://github.com/moonrepo/starbase/blob/master/crates/utils/src/glob.rs#L17 This should be avoiding traversing into those folders.

I haven't tried it, but you can also do apps/*/*/moon.yml.

@dudicoco
Copy link
Author

dudicoco commented Dec 1, 2024

@milesj apps/*/*/moon.yml doesn't work, it doesn't detect the projects.
But even if it did it wouldn't be a sufficient solution since some projects don't have moon.yml and rely on inherited tasks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants