bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

find, fts: dramatical improvement of speed in find


From: Askar Safin
Subject: find, fts: dramatical improvement of speed in find
Date: Thu, 16 Apr 2020 19:33:44 +0300

Hi. I applied the following patch to fts.c from latest revision of gnulib ( 
47bf2cf3184027c1eb9c1dfeea5c5b8b2d69710d ):

diff --git a/lib/fts.c b/lib/fts.c
index ade8c3349..70b424dea 100644
--- a/lib/fts.c
+++ b/lib/fts.c
@@ -1514,7 +1514,7 @@ mem1:                           saved_errno = errno;
                         bool skip_stat = (ISSET(FTS_PHYSICAL)
                                           && ISSET(FTS_NOSTAT)
                                           && DT_IS_KNOWN(dp)
-                                          && ! DT_MUST_BE(dp, DT_DIR));
+                                          && ! DT_MUST_BE(dp, DT_DIR)) || 
(ISSET(FTS_LOGICAL) && ISSET(FTS_NOSTAT) && DT_IS_KNOWN(dp) && ! DT_MUST_BE(dp, 
DT_DIR) && ! DT_MUST_BE(dp, DT_LNK));
                         p->fts_info = FTS_NSOK;
                         /* Propagate dirent.d_type information back
                            to caller, when possible.  */

(If my mail client damaged this patch, you can see it here: 
http://paste.debian.net/hidden/c4eaca5b/ )
Then I copied this patched fts.c to sources of "find" and "find" started to 
work significantly faster.
Idea is this: if we are in FTS_LOGICAL mode, we don't need "stat" if we know 
this is not directory or symlink.
Of course, I don't fully understand fts.c code, so, please, carefully review 
patch and make any needed additional changes (say, to comments).

I got time decrease from 14.16 s to 9.21 s when searching in my home directory 
using this command:

time -p sudo /tmp/sidabcn/root/findutils/find/find -O3 -L /home/user '(' -path 
'/home/user/Downloads' -o -path '*/.git' -o -path '*/Default' -o -path 
'*/dev/fd' -o -path '/home/user/opt' -o -path '*/node_modules' ')' -prune 
-false -o -type f > /tmp/st

(Of course, I don't want to share my home dir, so you will not be able to 
reproduce my test, but you can still try to type something like "find -O3 -L 
/home")

==
Askar Safin
https://github.com/safinaskar

reply via email to

[Prev in Thread] Current Thread [Next in Thread]