-
-
Notifications
You must be signed in to change notification settings - Fork 815
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
fd without pattern is much slower than find #304
Comments
@vandenoever Is there any way you can reproduce these results on a public corpus? |
I'd try the Linux kernel. If that fails to show a difference, then I'd try the chromium source tree. |
Here's the measurements for linux-4.17 source code. The effect with cold cache is less pronounced but still large. warm$ hyperfine --warmup 3 'fd -HI -t f . .' 'fd -HI -j1 -t f . .' 'find . -type f'
Benchmark #1: fd -HI -t f . .
Time (mean ± σ): 156.2 ms ± 3.0 ms [User: 270.4 ms, System: 298.3 ms]
Range (min … max): 151.3 ms … 164.7 ms
Benchmark #2: fd -HI -j1 -t f . .
Time (mean ± σ): 353.9 ms ± 10.5 ms [User: 258.3 ms, System: 281.8 ms]
Range (min … max): 338.9 ms … 370.6 ms
Benchmark #3: find . -type f
Time (mean ± σ): 76.7 ms ± 1.3 ms [User: 24.0 ms, System: 52.2 ms]
Range (min … max): 75.3 ms … 80.7 ms
Summary
'find . -type f' ran
2.04x faster than 'fd -HI -t f . .'
4.61x faster than 'fd -HI -j1 -t f . .' cold$ hyperfine --prepare 'sync; echo 3 | sudo tee /proc/sys/vm/drop_caches' 'fd -HI -t f . .' 'fd -HI -j1 -t f . .' 'find . -type f'
Benchmark #1: fd -HI -t f . .
Time (mean ± σ): 987.8 ms ± 15.8 ms [User: 394.4 ms, System: 1279.4 ms]
Range (min … max): 962.6 ms … 1007.4 ms
Benchmark #2: fd -HI -j1 -t f . .
Time (mean ± σ): 1.788 s ± 0.016 s [User: 413.6 ms, System: 920.6 ms]
Range (min … max): 1.758 s … 1.806 s
Benchmark #3: find . -type f
Time (mean ± σ): 736.7 ms ± 11.2 ms [User: 49.0 ms, System: 174.7 ms]
Range (min … max): 725.2 ms … 756.9 ms
Summary
'find . -type f' ran
1.34x faster than 'fd -HI -t f . .'
2.43x faster than 'fd -HI -j1 -t f . .' |
Thank you very much for reporting this. Which version of I can not reproduce these results on my home directory:
Will try the Linux Kernel soon. Did you clone https://github.com/torvalds/linux or just download the 4.17 source code? |
I'm running 7.0.0. I got 4.17 as tar.xz from kernel.org. What's your average file size? Perhaps it's related to number of files per directory. My home dir has 1.4M files in 150k directories so an average of 10 files per directory. Why does your benchmark command have a non-zero exit code? |
@sharkdp: is fd also faster with |
This can be ignored. I have a single test-folder (for
Mine is 920k files in 180k folders (5 files per directory). Why do you think it could be related to the ratio files/directories (I'm not saying it isn't)?
I ran the benchmarks for the same dataset. While the effect is less dramatic, I can reproduce your results for a warm cache:
However, for a cold cache, I get the following:
Interestingly, the Linux kernel has a files/directories ratio of about 14, so there might very well be a correlation.
Still, this seems to be a case where |
There are two actions going on reading a directory and reading file metadata. I'm not in a hurry to have this fixed. It was the first thing I noticed when I tried out Since Perhaps using a Mutex to coordinate the output instead of using channels is faster, because you can then perhaps reuse buffers and avoid allocations. |
Thank you for the useful tips! I think the main issue might be the actual printing of the results in
... while
I'm pretty sure we can find some ways to optimize Edit: another thing I have noticed in the past (although this will not affect the benchmarks above): If you really have a lot of search results, the output of |
I know we've ruled it out as the bottleneck, but to share a bit of greybeard folklore: back in my sysadmin days (and this was before microbenchmarking was the norm), I was always told to use |
Glancing at the printing functions, there is definitely some room to optimize I think. For my own use cases, I found that most of the standard path functions in |
@BurntSushi Exactly, that was what I was thinking about. As a bonus, this would also solve #295. |
I found a very simple optimization in 50a2bab which (possibly together with some other improvements) brings the multi-core version of fd-7.1.0 up to the same speed as
I still need to look at optimizations in |
I'm going to close this for now. The current version of |
I often use
find
to list files. Doing this infd
is much slower. Here are some results for listing all files in my home directory with warm and cold cache. The directory is on btrfs on Linux 4.15.15.find
is about twice as fast in both cases and uses about 10% of the cpu cycles thatfd
uses.Here is a screenshot of the CPU and IO during the run with cold cache.
The text was updated successfully, but these errors were encountered: