]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
properties: Skip found set building for nominal case
authorChris Down <chris@chrisdown.name>
Fri, 24 Jul 2026 23:08:16 +0000 (16:08 -0700)
committerChris Down <chris@chrisdown.name>
Fri, 31 Jul 2026 23:41:53 +0000 (16:41 -0700)
bus_message_print_all_properties() inserts every name it walks into the
found-properties set, but the set is only used to report missing requested
properties at debug level.

Request the set from systemctl only when properties were specified and debug
logging is enabled, avoiding the unnecessary work in normal operation.

In my tests with `systemctl show` over 160 units this brings the
instructions retired from 1167.8M down to 992.6M, a reduction of 15.0%.
The output is unchanged.

src/systemctl/systemctl-show.c

index 82b85688133653c10f4c5b45a1bdff2dfc2c7308..464955e160199795b64912ce5472cfda43d390c4 100644 (file)
@@ -2336,6 +2336,7 @@ static int show_one(
                 .io_read_bytes = UINT64_MAX,
                 .io_write_bytes = UINT64_MAX,
         };
+        bool collect_found_properties;
         int r;
 
         assert(path);
@@ -2387,13 +2388,18 @@ static int show_one(
         if (r < 0)
                 return log_error_errno(r, "Failed to rewind: %s", bus_error_message(&error, r));
 
-        r = bus_message_print_all_properties(reply, print_property, arg_properties, arg_print_flags, &found_properties);
+        /* The found properties set is expensive and only used for debug logging, so collect it only when needed. */
+        collect_found_properties = DEBUG_LOGGING && !strv_isempty(arg_properties);
+
+        r = bus_message_print_all_properties(reply, print_property, arg_properties, arg_print_flags,
+                                             collect_found_properties ? &found_properties : NULL);
         if (r < 0)
                 return bus_log_parse_error(r);
 
-        STRV_FOREACH(pp, arg_properties)
-                if (!set_contains(found_properties, *pp))
-                        log_debug("Property %s does not exist.", *pp);
+        if (collect_found_properties)
+                STRV_FOREACH(pp, arg_properties)
+                        if (!set_contains(found_properties, *pp))
+                                log_debug("Property %s does not exist.", *pp);
 
         return 0;
 }