Tighten up nohoist rules to speed up yarn #1
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.
Summary
Bring Yarn install times down from 30mins to 1 minute.
Details
Hi @sibelius , I'm in the process of writing up a blog post detailing how to improve yarn times and I saw your repro and thought I could help.
The key to the improving the yarn speeds here is to tighten up nohoist rules to speed up yarn.
From the original blog post when nohoist was released:
We need the nohoist rules so that react-native and react-native native dependencies can be linked easily and found by cli tools.
In the docs and various github issues the recommended pattern for adding nohoist rules is the way you have it setup:
The problem starts to appear when we add modules that depend on react native:
The nohoist rules mean that we now have two versions of react-native being installed. And because we have the deep nohoist rule we are also nohoisting all of react-native's 64 dependencies for every copy of react native.
The more packages you add that depend on react-native the worse the problem gets.
The solution is to tighten up the nohoist rules. It's a little harder to maintain. And sometimes you have to deal with hoisting issues manually but it's worth it to make install times bare-able (until yarn 2 supports react native 🐈 .
So for the project above the rules become:
Results
Most of the install time is the process of copying files. The best proxy I've found for cutting install times —without having to wait for the install to finish— is the progress bar shown during the yarn install. It shows the number of files being copied/linked out of the total. It's actually shown a few times but we can focus on when it has the largest numbers.
Note: Both yarn times are with a yarn cache and yarn.lock file but without node_modules.
Other notes
In the PR I've added all to the nohoist rules for all react-native packages. This is simpler and does the job but could start to slow down after more packages and apps are added. In our monorepo, we normally only nohoist a package if react native, xcode or gradle complain. Either way works fine. :)
If you have any feedback about this info let me know and I'll incorporate it into the blog post. :)