-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
du: our implementation is slower than GNU's #6845
Comments
@jesseschalken has been working on it |
With the three PR, we are almost the same level:
|
a profile with the 3 PR https://share.firefox.dev/4fdZpVX |
Hey! It's been almost 3 years since the last time I contributed to this repository, I wanted to get familiar with the repository again, so I decided to tackle this issue. I made some modifications, but I'm not sure, adding more parallelism in My optimizations/changes was mostly based around this idea:
With these changes, I was able to make it faster than the GNU version.
I ran the tests on gecko-dev repository. Device: Also a good thing that all the tests are still passing without any modification to them:
I haven't fully polished and documented the changes yet, also I wasn't sure of this optimization is something we want so I didn't create a PR, yet. Also I'm still unsure about the output ordering, in the current implementation we were already printing output in a separate thread, now we are also traversing in multiple threads, the ordering of the output is not deterministic, could it be harmful? |
Impressive! I think it should be ordered but not 100% sure |
IIRC at minimum the directories given on the command-line need to be done in-order. I believe the actual output other than that is pretty much random (filesystem order basically), but it goes through each directory recursively before moving on to the next one. If you've got: src/
some/
data/
foo.txt
bar.txt
target/
baz.txt The output order will be something like:
Note that the directories Assuming what I remember here is actually the case, I imagine there are probably some scripts that actually depend on the output drilling down through an entire directory before moving on. Depending on how much memory is acceptable to consume, all the paths could be stored in a list or something and sorted before being displayed, since I'm pretty sure the actual order of the files within a given directory doesn't matter. |
Exactly, whatever the FTS (gnulib
Your reasoning is also right on this, but the output is quite different than that, if I create this:
It actually returns this:
I was sure that the output order is deterministic, but I wasn't sure that it had a particular order, so I did a little digging. It turns out there is an order indeed for the output; it is doing a post-order hierarchy walk and printing in that order. It is also about the efficiency as you said. So the actual flow goes like this:
The reason behind this is; we need the sizes of all subdirectories before we can compute the total size of the parent directory. In my implementation(also the current implementation), we're already doing a form of post-order traversal since we must process subdirectories recursively before adding their sizes to the parent directory, if we run on single thread it still matches the GNU output
I think buffering things before displaying would be a bottleneck in that scenario because we still need to rely on single thread to display all the buffered files, also time to display first byte would not be optimal since there is going to be an initial delay. Also I'm wondering if this is ordering is really that important, since:
Another idea that comes to my mind, can this be added as a new feature as a replacement for |
I would not bet on this ;)
yeah, i think adding an option would be fine |
I just realized that, even running |
On firefox source code (lot of files and directories):
seems that we regressed:
The text was updated successfully, but these errors were encountered: