From 5663ddaed7f7d89236cf0ef4a634c3828518108c Mon Sep 17 00:00:00 2001 From: Chris Down Date: Fri, 24 Jul 2026 16:08:16 -0700 Subject: [PATCH] properties: Skip found set building for nominal case 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 | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/systemctl/systemctl-show.c b/src/systemctl/systemctl-show.c index 82b8568813..464955e160 100644 --- a/src/systemctl/systemctl-show.c +++ b/src/systemctl/systemctl-show.c @@ -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; }