-
Notifications
You must be signed in to change notification settings - Fork 637
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
Default metro resolver slower than MetroSymlinksResolver in a monorepo #1208
Comments
Hi @abejfehr - thanks for taking the time to deep-dive into this - it's always good to find out how Metro is performing in setups "in the wild" outside Meta, and particularly in this detail. A couple of high level points -
|
Hi @abejfehr - Metro 0.80.6 was released yesterday with the two path manipulation performance improvements I mentioned. If you're using RN 0.73 you should get that update by refreshing your lockfile - it'd be interesting to see whether that helps. |
Unfortunately we're using 0.72 at this time, but thank you for letting me know! I'll also see if I can get the information you asked for previously about "what work Metro isn't doing as a result of using |
Hey, just reporting an update. In our large project we've also seen significant improvements with Edit: just found out about this 🎉 |
We just upgraded to React Native 0.73, and Metro 0.80.12. I've now tested the default Metro resolver, the aforementioned Thanks for the performance improvements in Metro 0.80.12! I'm going to close this issue |
Do you want to request a feature or report a bug?
I'm not sure if this counts as a bug exactly, but it's a performance issue for monorepos in cases where most of the app's code (including node_modules) is outside the directory that the app is in.
What is the current behavior?
When building an app bundle with metro using the default metro resolver in a monorepo, the build times are a lot longer than if you use
@rnx-kit/metro-resolver-symlinks
.If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can
yarn install
andyarn test
.To reproduce this somewhat effectively, you'd need a really large monorepo that looks something like this:
and in your metro config, something like this:
If you bundle the app using a command like:
and analyze the generated .cpuprofile file in speedscope.net in the "Left Heavy" view, you can see that a non-trivial amount of time is spent in here:
It appears to be spending a lot of time (in this case over a minute because I'm using only 1 worker thread) in
relative
in (ironically)fast_path.js
here, called by TreeFS here.I think that happens because the files being imported exist outside of #rootDir, which in this example is
/apps/mobile
, whereas most of the code is in/libs/...
in this repo.Even though we have no need for resolving symlinks, we use MetroSymlinksResolver because it's just more performant in this scenario.
Possibly related: if you add a
console.log
inside therelative
function and log the args, you see that it seems to run with every permutation of extension, e.g.^ this is an actual portion (with some path redactions) of that log of it resolving
react
It doesn't feel very effiicent to me, and it might be nice if there was a way to call
relative
once on the path and append the path with every permutation of extension on the already-relative'd version of the path, but I don't how involved a change like that might be.What is the expected behavior?
Ideally, the default resolver would be closer to the same speed as MetroSymlinksResolver in the case of a monorepo where most of the app's code is outside of #rootDir.
Please provide your exact Metro configuration and mention your Metro, node, yarn/npm version and operating system.
I've given an abridged version of the metro configuration above.
OS and package manager doesn't matter much, but I use macOS and yarn 1.
The text was updated successfully, but these errors were encountered: