Repository navigation
Spawn child process for rimraf (speeds up lerna clean) - #547
Conversation
| @logger.logifyAsync() | ||
| static rimraf(filePath, callback) { | ||
| rimraf(filePath, callback); | ||
| ChildProcessUtilities.spawn(join(__dirname, "../node_modules/.bin/rimraf"), [filePath], {}, callback); |
There was a problem hiding this comment.
Can do. Something like this?
const npmBin = ChildProcessUtilities.execSync("npm bin", {cwd: __dirname});
ChildProcessUtilities.spawn(join(npmBin, "rimraf"), [filePath], {}, callback)
7a6195d to
91e29f4
Compare
Improves performance of `lerna clean` on large projects.
91e29f4 to
04aed0f
Compare
|
@doug-wade updated to use |
doug-wade
left a comment
There was a problem hiding this comment.
This seems reasonable to me
| @logger.logifyAsync() | ||
| static rimraf(filePath, callback) { | ||
| rimraf(filePath, callback); | ||
| ChildProcessUtilities.exec("npm bin", {cwd: __dirname}, (err, npmBinPath) => { |
There was a problem hiding this comment.
Can/should we cache this? Seems wasteful to shell out for it every time when it's constant.
There was a problem hiding this comment.
I had that thought too, and then decided that this was probably roughly equivalent to a shell script that did something like $(npm bin)/rimraf /some/dir/node_modules, so I didn't bother fixing it. It seems like the cost of running rimraf (node-based filesystem walking and unlinking) would dwarf the npm bin exec for most projects anyway?
If we want to cache it, I guess we'd do that in a module-level variable in FileSystemUtilities? Wouldn't be hard to add.
There was a problem hiding this comment.
Yeah, maybe premature optimization.
|
Thanks @roblg! |
lerna clean)
|
@roblg I've edited the title of the PR as prep for inclusion in the changlog. Please tweak as you see fit. |
This is necessary to make lerna#547 work when Lerna is installed locally. Lerna is looking for the `rimraf` executable in its own `$(npm bin)` directory, but npm 3+ hoists the executable to the _containing_ package's `.bin` so `rimraf` winds up not being found. This patch bundles `rimraf` _with_ Lerna so it's always where we expect it.
These noop rimrafs were cheap before lerna#547, but they're expensive now.
These noop rimrafs were cheap before lerna#547, but they're expensive now.
These noop rimrafs were cheap before #547, but they're expensive now.
|
This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Improves performance of
lerna cleanon large projects.I fully recognize that this could be contentious, but I also didn't see an issue/conversation about it, so I figured it couldn't hurt to submit. This shaves ~19s (21% improvement!) off our monorepo build with
lerna:For the purposes of conversation, I did the simplest thing I could think of, but I'm also open to exploring alternative solutions. I suspect that shelling out to
rmand/or the windows equivalent would be even faster still, but I'll resist the urge to do that. 😁Update: One downside to this approach is that
rimrafisn't a require-time dependency anymore, which might cause static analysis (or a human with a restrictive regex) to erroneously conclude that it's not actually being used.Update 2: Added a couple of additional timings for posterity (
--concurrency 3for external,--concurrency 1for internal).