dirEntries removes entire branches of empty directories

kdevel kdevel at vogtner.de
Mon Nov 14 22:41:33 UTC 2022


On Monday, 14 November 2022 at 21:05:01 UTC, kdevel wrote:
> [...]
> the runtimes are
>
>    ftw       : 98 ms, 470 ÎŒs, and 2 *beeep*
>    dirEntries: 170 ms, 515 ÎŒs, and 2 *beeep*
>
> (to be continued)

When I examine the process with strace it appears that the ftw 
version gets the whole information from readdir alone. The 
dirEntries version seems to call lstat on every file (in order to 
check that it is not a symlink)

Breakpoint 1, 0xf7cc59d4 in lstat64 () from 
[...]gcc-12.1/lib/libgphobos.so.3
(gdb) bt
#0  0xf7cc59d4 in lstat64 () from 
[...]gcc-12.1/lib/libgphobos.so.3
#1  0xf7a5269b in std.file.DirEntry._ensureLStatDone() () from 
[...]gcc-12.1/lib/libgphobos.so.3
#2  0xf7a5276a in std.file.DirEntry.linkAttributes() () from 
[...]gcc-12.1/lib/libgphobos.so.3
#3  0xf7a528c9 in std.file.DirIteratorImpl.mayStepIn() () from 
[...]gcc-12.1/lib/libgphobos.so.3
#4  0xf7a545ae in std.file.DirIteratorImpl() () from 
[...]gcc-12.1/lib/libgphobos.so.3
#5  0xf7a5466e in core.internal.lifetime() () from 
[...]gcc-12.1/lib/libgphobos.so.3
#6  0xf7a546ef in core.internal.lifetime() () from 
[...]gcc-12.1/lib/libgphobos.so.3
#7  0xf7a54726 in core.lifetime() () from 
[...]gcc-12.1/lib/libgphobos.so.3
#8  0xf7a54762 in std.typecons() () from 
[...]gcc-12.1/lib/libgphobos.so.3
#9  0xf7a547d6 in std.typecons() () from 
[...]gcc-12.1/lib/libgphobos.so.3
#10 0xf7a54811 in std.file.DirIterator.__ctor() () from 
[...]gcc-12.1/lib/libgphobos.so.3
#11 0xf7a54882 in std.file.dirEntries() () from 
[...]gcc-12.1/lib/libgphobos.so.3
#12 0x08088e25 in direntrybenchmark.directoryWalk_dirEntries() 
(root=..., dump=false) at direntrybenchmark.d:111

and after that an additional stat on the same file in order to 
check if it is a directory:

Breakpoint 2, 0xf7cc5954 in stat64 () from 
[...]gcc-12.1/lib/libgphobos.so.3
(gdb) bt
#0  0xf7cc5954 in stat64 () from [...]gcc-12.1/lib/libgphobos.so.3
#1  0xf7a527e1 in std.file.DirEntry._ensureStatOrLStatDone() () 
from [...]gcc-12.1/lib/libgphobos.so.3
#2  0xf7a5287a in std.file.DirEntry.isDir() () from 
[...]gcc-12.1/lib/libgphobos.so.3
#3  0x08088e6c in direntrybenchmark.directoryWalk_dirEntries() 
(root=..., dump=<optimized out>) at direntrybenchmark.d:112
#4  0x08089105 in __lambda7 (__capture=0xf7411000) at 
direntrybenchmark.d:158
#5  0x0809f8aa in benchmark (n=1, __capture=<optimized out>)
     at 
/md11/sda2-usr2l/gcc-12.1/lib/gcc/x86_64-pc-linux-gnu/12.1.0/include/d/std/datetime/stopwatch.d:421
#6  __foreachbody9 (__capture=0xf7411000, __applyArg0=..., 
__applyArg1=...) at direntrybenchmark.d:162
#7  0xf7c98bd9 in _aaApply2 () from 
[...]gcc-12.1/lib/libgphobos.so.3
#8  0x0808dee1 in direntrybenchmark.main_() (args=...) at 
direntrybenchmark.d:161




More information about the Digitalmars-d-learn mailing list