]> Kevux Git Server - kevux-tools/commitdiff
Update: Pass 0 to f_directory_remove() to avoid nftw() calls.
authorKevin Day <Kevin@kevux.org>
Sun, 13 Apr 2025 19:53:27 +0000 (14:53 -0500)
committerKevin Day <Kevin@kevux.org>
Sun, 13 Apr 2025 20:02:03 +0000 (15:02 -0500)
The `fl_directory_do()` already is taking care of the recursive delete.
The `f_directory_remove()` should not need to recurse.

The `nftw()` uses a lot of resources and slows down the speed even when the directory is empty.

The massif-visualizer shows that with `nftw()` there are two ~548.8 Kb spikes to remove empty directories.
Without the `nftw()` there is only a single 64Kb spike to remove the same empty directories.

The time taken with `nftw()` takes about 4e+06.
The time taken without `nftw()` takes about 1.6e+06.

The memory usage according to valgrind with `nftw()` is about 84 allocs, 84 frees, 3,303,959 bytes allocated.
The memory usage according to valgrind without `nftw()` is about 74 allocs, 74 frees, 497,999 bytes allocated.

The command I used to test this is:
```
clear ; md a/b/{c/d,e/f} && touch xxx && touch a/b/file.txt && valgrind remove a/b xxx -r ; t a
clear ; md a/b/{c/d,e/f} && touch xxx && touch a/b/file.txt && valgrind --tool=massif remove a/b xxx -r ; t a
```

sources/c/program/kevux/tools/remove/main/operate.c

index b896c483affb9fb99bd4e7e32e581c31118526b7..5028ed5da4bb61d62d0fb954ee3b219d38494d3b 100644 (file)
@@ -448,7 +448,7 @@ extern "C" {
     const f_string_static_t target = (flag_operate & kt_remove_flag_file_operate_follow_d) ? main->cache.buffer : path;
 
     status = flag_operate & kt_remove_flag_file_operate_directory_d
-      ? f_directory_remove(target, (main->setting.flag & kt_remove_main_flag_recurse_d) ? kt_remove_depth_max_d : 0, F_false)
+      ? f_directory_remove(target, 0, F_false)
       : f_file_remove(target);
 
     if (F_status_is_error(status)) {