Make "Linking dependencies" faster on Windows (in some cases) #2958
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
Motivation: Yarn is slow on one of my windows machines (but not others) with Linking dependencies... that can take minutes, so I tried to find the cause.
Turns out that Yarn was sometimes always copying every file because it's hiting this node bug: nodejs/node#2069 that is windows specific.
In
fs.js
,fs.utimes
is used after the file copy incopyBulk
to set themtime
and checked to avoid extra copies inbuildActionsForCopy
but due to the bug the dates won't match even for files that were just copied by Yarn.The bug is subtle because it doesn't reproduce on a clean system as Yarn would have downloaded the packages and copied the extracted version to the cache. In this case it would use the same buggy
utimes
version and will set the milliseconds ofmtime
for the source in the cache. But if the file modification time is changed for any reason (Antivirus maybe ?), Yarn will never be able to determine that they are the same again and will always do the copy.Test plan
find . -type f -exec touch {} +
)yarn add lodash
using the released version (0.21.3) in one dir and measured the time over a few runs : ~14s, the progress bar in Linking dependencies... dominates the timeyarn add lodash
using my branch in one dir and measured the time over a few runs: ~6s, the progress bar in Linking dependencies... starts & finish near immediately