]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hardlink: fix performance regression (inefficient signal evaluation)
authorKarel Zak <kzak@redhat.com>
Tue, 29 Apr 2025 10:29:32 +0000 (12:29 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 29 Apr 2025 10:53:55 +0000 (12:53 +0200)
During work on better verbose output, I found a regression between
v2.40 and v2.41 (and v2.42). In the new version, hardlink is 3-4 times
slower.

The problem is in the function where we verify signals. It calls the
function signal() even though no signal is delivered. It's called in
code loops where hardlink scans files, making it a performance-sensitive
area.

Another significant performance improvement is using an inline function
for handle_interrupt().

This simple patch improves hardlink performance by 10 times.

Fixes: http://github.com/util-linux/util-linux/commit/1453200e22dd4ec858be027653c167225f2fb358
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/hardlink.c

index 7e7beffddd130faca7c1e62763cac0c26e53b92b..d32d0c6da0e5f44b53d3214a533806edeab7c4e9 100644 (file)
@@ -433,9 +433,11 @@ static void print_stats(void)
 /**
  * handle_interrupt - Handle a signal
  */
-static void handle_interrupt(void)
+static inline void handle_interrupt(void)
 {
        switch (last_signal) {
+       case 0:
+               break;
        case SIGUSR1:
                print_stats();
                putchar('\n');