Conversation
|
@nfischer: Ready for Review. |
| } else { | ||
| common.error('not a directory: ' + dir); | ||
| } | ||
| } catch (e) { |
There was a problem hiding this comment.
Just tested this out, and it looks like both common.error() statements get run if the user types something like cd('file.txt') (where file.txt is a regular file that exists). Could we fix this?
There was a problem hiding this comment.
Oh, yeah. I'll fix that.
|
Tried this out. I saw a slight perf win, which is awesome! I just have one comment above about correctness of error messages. If that gets fixed, I can merge |
|
Also, just tried this, and it has the output |
|
@nfischer: What did you run exactly? |
|
Here's what I ran: |
|
@ariporad pinging this to see if the issue with error messages has been fixed yet. |
|
@nfischer: I'm not experiencing the behavior that you're describing. I tried both your scripts, they work as expected for me. (The tests are also passing). |
|
I'll try again today. The issue is with stderr output, not the value of |
|
@ariporad I just updated the code a bit to improve performance a bit more. We should rename this PR to "only run It turns out you were right. The incorrect error message isn't due to your code, it's due to a bug that was introduced in #357. I'm currently trying to work out a fix for this (it shouldn't be too hard). Expect to see the fix sometime tonight. Here's some perf stats I saw on my machine. This is the script I ran (named require('shelljs/global');
for (var k=0; k<20000; k++) {
cd('dir/'); // this is a directory that exists
cd('..');
}Here's the perf I saw: # for the original implementation
$ time -p node cd.js
real 2.61
user 2.50
sys 0.13
# for your revision
$ time -p node cd.js
real 2.11
user 1.98
sys 0.15
# for my revision
$ time -p node cd.js
real 1.96
user 1.90
sys 0.07I also tested things with cd'ing into a file and into a non-existent directory. I saw perf wins for my revision there as well, but this is mainly designed to optimize for the common case. I don't think performance is as big of a concern for when the command errors-out (and with Merge at will. |
|
Update: I thought a bit more about the error message, and I decided that it's probably easier to fix the issue here than elsewhere. So I updated the PR with the fix. This will now only output the proper error message. Perf stats are still the same. |
|
@nfischer: LGTM, but one thing just occurred to me: should we eliminate tey/catch statements? Might be faster (http://git.io/fast-v8) |
|
@ariporad I think try-catch may be necessary here. I know it adds some performance overhead, but |
|
Ok |
perf(cd): only run `stat` once
This increases performance somewhat