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

Optimize buildActionsForCopy routine #2657

Merged
merged 2 commits into from
Apr 20, 2017
Merged

Conversation

mourner
Copy link
Contributor

@mourner mourner commented Feb 7, 2017

Summary

Makes linking faster by reducing the number of file system calls in the buildActionsForCopy routine which synchronizes existing node_modules tree with the ideal one.

In my test runs (on yarn itself, and on another big project), it saves about 400ms when running yarn without a lock file (or during upgrade).

  • Remove redundant fs.exists (in favor of lstat which is called later anyway)
  • Remove unnecessary fs.access (which does nothing — it's a placeholder in the code, so should be commented)
  • Remove deeper directory traversal for possibleExtraneous since it should be populated with the same values later in the queue anyway.
  • Avoid calling mkdirp if we know the destination folder already exists.

cc @bestander

Test plan

Not necessary — it doesn't change the results of exported functions. Let's see if this PR passes the CI tests.

@mourner
Copy link
Contributor Author

mourner commented Feb 8, 2017

In the tests, there's only one failure (resolving https://github.com/babel/babel-loader.git#greenkeeper/cross-env-3.1.4) and it seems unrelated to the PR changes because the same failure happens in other recent PRs.

Copy link
Member

@bestander bestander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is very useful, thanks a lot for improving it.
Just a few nits

src/util/fs.js Outdated
let destStat;
try {
destStat = await lstat(dest);
} catch (e) {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there needs to be an explanation for a muted exception.
Could you add a one line comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sure. Basically, fs.exists is deprecated in Node, which recommends using fs.stat with error handling instead. In this case destStat will be undefined if error occurs during lstat.

src/util/fs.js Outdated
// EINVAL access errors sometimes happen which shouldn't because node shouldn't be giving
// us modes that aren't valid. investigate this, it's generally safe to proceed.

// if (srcStat.mode !== destStat.mode) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it was left there as something to investigate in future, so I left it as a comment. Should I remove?

@mourner
Copy link
Contributor Author

mourner commented Feb 9, 2017

@bestander addressed your first comment and rebased on master, so this PR should be good to go. Regarding the read mode leftover — it was there before my changes (as sort of a TODO to investigate), so I'm leaving it there as a comment. @kittens introduced it in 4bbc653.

@mourner
Copy link
Contributor Author

mourner commented Feb 9, 2017

The AppVeyor build failed with the following error, which seems unrelated to the PR changes:

should expose npm_config_argv environment variable to lifecycle scripts for back compatibility with npm (#684)

// EINVAL access errors sometimes happen which shouldn't because node shouldn't be giving
// us modes that aren't valid. investigate this, it's generally safe to proceed.

/* if (srcStat.mode !== destStat.mode) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what should we do with this code?
No reason to keep it commented out.

Copy link
Contributor Author

@mourner mourner Feb 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no one from the Yarn team is willing to investigate cases where it's unsafe to proceed when the file read modes don't match, I'm OK removing the code. I'd leave the text comment above though, just in case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit was added by @kittens in 4bbc653.
I'll ping him to give some context

Copy link
Member

@bestander bestander Feb 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping me in 2 days if there is no answer, then let's just merge with this code removed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bestander Ping 😉

Copy link
Member

@bestander bestander Feb 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let's remove the commented out code and get back to it if we see errors reported.

@mourner
Copy link
Contributor Author

mourner commented Mar 24, 2017

Sorry for the late response — I should probably wait before master starts passing CI tests more reliably before rebasing and suggesting to merge. Most recent commits in master fail on all servers.

@bestander
Copy link
Member

We have a few flaky tests but master got stable enough to get the signal if a PR is breaking something, so let's give this one one more try.

@bestander
Copy link
Member

@mourner, would you rebase?

@mourner
Copy link
Contributor Author

mourner commented Apr 10, 2017

@bestander yes, will do!

@bestander bestander merged commit 9a6afe1 into yarnpkg:master Apr 20, 2017
@mourner
Copy link
Contributor Author

mourner commented Apr 21, 2017

@bestander sorry for getting out of the loop. I see that Travis started having a failed test after this merge — do you think this is a consequence of this PR or an unrelated intermittent failure?

FAIL  __tests__/commands/add.js (174.708s)
  ● add with new dependency should be deterministic 3

@arcanis
Copy link
Member

arcanis commented Apr 21, 2017

It's probably related, previous tests weren't subject to this (it's usually timeout that kill our tests)

mourner added a commit to mourner/yarn that referenced this pull request Apr 21, 2017
@mourner
Copy link
Contributor Author

mourner commented Apr 21, 2017

OK, submitting a PR to revert a few lines that caused the failure until we figure out what's going on.

@mourner mourner deleted the optimize-sync branch April 21, 2017 15:34
sebmck pushed a commit that referenced this pull request Apr 21, 2017
@sebmck
Copy link
Contributor

sebmck commented Apr 21, 2017

There's a bunch of lint warnings on master introduced by this PR, could you open a PR to fix them?

This was referenced Apr 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants