From 24189e2cd3fadf2dc1727410221c3ffd75e8e320 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sun, 13 Apr 2025 14:53:27 -0500 Subject: [PATCH] Update: Pass 0 to f_directory_remove() to avoid nftw() calls. 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/c/program/kevux/tools/remove/main/operate.c b/sources/c/program/kevux/tools/remove/main/operate.c index b896c48..5028ed5 100644 --- a/sources/c/program/kevux/tools/remove/main/operate.c +++ b/sources/c/program/kevux/tools/remove/main/operate.c @@ -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)) { -- 1.8.3.1