From 2832d8e8ea84bc5f1106808b39c54d58038ee073 Mon Sep 17 00:00:00 2001 From: Jerry Zhao Date: Tue, 3 Nov 2026 06:32:49 +0000 Subject: [PATCH] perf(io): construct submission status after SQE preparation Keep one named return object for fast and queued submissions, but construct it after direct preparation. GCC LTO can then eliminate successful send status stack traffic without adding a protected stack temporary in the non-LTO backend. Run the existing suites without new tests: 96 normal and 123 bypass-capable tests pass. The isolated AArch64 GCC 13 O3 LTO send success paths lose four instructions; non-LTO SubmitSend retains its instruction count and frame. --- src/io/io_uring_backend.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/io/io_uring_backend.cpp b/src/io/io_uring_backend.cpp index 21dba19..65ff574 100644 --- a/src/io/io_uring_backend.cpp +++ b/src/io/io_uring_backend.cpp @@ -247,20 +247,22 @@ void IoUringBackend::UnregisterStorageResources() { template absl::Status IoUringBackend::SubmitOrQueue(Prepare prepare) { - // Share one return object with the slow path. Returning its Status by value - // would otherwise introduce a protected stack temporary in the common path - // with GCC, even though the SQE itself is no longer stack-allocated here. - absl::Status status; + bool prepared = false; // Older accepted work retains priority. Preparation runs synchronously and // is never retained; only the prepared descriptor can enter the queue. // Never submit/reap here: callers install their continuation afterwards. if (initialized_ && pending_io_.empty()) [[likely]] { if (auto* sqe = AcquireSqe()) [[likely]] { prepare(sqe); - return status; + prepared = true; } } - QueuePrepared(prepare, &status); + // Construct the shared return object after SQE writes so GCC LTO can fold + // the successful result in callers. Keep one named return object: returning + // a separate Status from the slow path adds a protected stack temporary + // without LTO. + absl::Status status; + if (!prepared) QueuePrepared(prepare, &status); return status; }