SpaceAnalyzer: Use fstatat instead of lstat

By using fstatat during file system analyzation instead of lstat, we
reduce the amount of work the kernel has to do for each stat call.

During profiling it came up that the kernel was spending a lot of time
resolving paths. Because each call to stat passed an absolute path the
kernel had to do the same work over and over again.

When using relative paths the kernel only has to resolve the relative
part as it can reuse the already resolved path of the base directory.
This commit is contained in:
Mart G 2021-05-14 21:29:21 +02:00 committed by Andreas Kling
parent 758085571f
commit f70d0f03de
Notes: sideshowbarker 2024-07-18 18:08:18 +09:00

View file

@ -22,6 +22,7 @@
#include <LibGUI/Menubar.h>
#include <LibGUI/MessageBox.h>
#include <LibGUI/Statusbar.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
@ -170,7 +171,7 @@ static void populate_filesize_tree(TreeNode& root, Vector<MountInfo>& mounts, Ha
int name_len = name.length();
builder.append(name);
struct stat st;
int stat_result = lstat(builder.to_string().characters(), &st);
int stat_result = fstatat(dir_iterator.fd(), name.characters(), &st, AT_SYMLINK_NOFOLLOW);
if (stat_result < 0) {
int error_sum = error_accumulator.get(errno).value_or(0);
error_accumulator.set(errno, error_sum + 1);