From 5941ecf767d0bab4aea63d0b58ba94783be34eaf Mon Sep 17 00:00:00 2001 From: AdrianKuriata Date: Wed, 29 Jul 2026 15:56:07 +0200 Subject: [PATCH] perf(cli): don't force info reads when the invocation sets something Structured output marks every info capability as requested, even when the command line only asked to set a value. On an Audeze Maxwell 2 that turns a 0.07 s write into 2.90 s, because the status read sends 21 packets at 60 ms intervals. Explicitly requested info still works, -b -s 20 -o json reports the battery. --- cli/main.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/cli/main.cpp b/cli/main.cpp index 7255980..61425a3 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -1031,10 +1031,26 @@ std::vector toLegacyDeviceList(std::vector& device return legacy; } +// Whether this invocation was asked to set something. +bool hasRequestedAction(const std::vector& devices) +{ + for (const auto& dev : devices) { + for (const auto& req : dev.feature_requests) { + if (req.type == CAPABILITYTYPE_ACTION && req.should_process) { + return true; + } + } + } + + return false; +} + // Enable info requests for extended output formats (JSON, YAML, ENV) +// Only for a pure query: the extra reads can cost far more than the action +// itself (Maxwell 2: -s 20 is 0.07 s, -s 20 -o json is 2.90 s). void enableExtendedInfoRequests(std::vector& devices, bool extended) { - if (!extended) + if (!extended || hasRequestedAction(devices)) return; for (auto& dev : devices) {