-
Notifications
You must be signed in to change notification settings - Fork 768
future-util: opts #31061
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
StephanDollberg
wants to merge
3
commits into
dev
Choose a base branch
from
stephan/future-util
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+153
−18
Open
future-util: opts #31061
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| // Copyright 2026 Redpanda Data, Inc. | ||
| // | ||
| // Use of this software is governed by the Business Source License | ||
| // included in the file licenses/BSL.md | ||
| // | ||
| // As of the Change Date specified in that file, in accordance with | ||
| // the Business Source License, use of this software will be governed | ||
| // by the Apache License, Version 2.0 | ||
|
|
||
| #include "base/seastarx.h" | ||
| #include "ssx/future-util.h" | ||
|
|
||
| #include <seastar/core/coroutine.hh> | ||
| #include <seastar/core/future.hh> | ||
| #include <seastar/testing/perf_tests.hh> | ||
|
|
||
| #include <stdexcept> | ||
|
|
||
| namespace { | ||
|
|
||
| constexpr size_t iterations = 10000; | ||
|
|
||
| template<typename Func> | ||
| ss::future<size_t> co_await_in_loop(Func func) { | ||
| perf_tests::start_measuring_time(); | ||
| for (size_t i = 0; i < iterations; ++i) { | ||
| co_await func(); | ||
| } | ||
| perf_tests::stop_measuring_time(); | ||
| co_return iterations; | ||
| } | ||
|
|
||
| // Input producers for ignore_shutdown_exceptions. | ||
| // | ||
| // Keep these out of line to preserve the producer call in each measured | ||
| // iteration. Already-resolved futures are the common path being measured. | ||
|
|
||
| // Available, successful future. | ||
| [[gnu::noinline]] ss::future<> input_ready() { return ss::now(); } | ||
|
|
||
| // Available future failed with a gate_closed_exception (a shutdown exception). | ||
| [[gnu::noinline]] ss::future<> input_gate_closed() { | ||
| return ss::make_exception_future<>(seastar::gate_closed_exception{}); | ||
| } | ||
|
|
||
| // Available future failed with an abort_requested_exception (a shutdown | ||
| // exception). | ||
| [[gnu::noinline]] ss::future<> input_abort_requested() { | ||
| return ss::make_exception_future<>(seastar::abort_requested_exception{}); | ||
| } | ||
|
|
||
| // Available future failed with a std::runtime_error: a non-shutdown exception | ||
| // that ignore_shutdown_exceptions must rethrow to the caller. | ||
| [[gnu::noinline]] ss::future<> input_runtime_error() { | ||
| return ss::make_exception_future<>(std::runtime_error("not shutdown")); | ||
| } | ||
|
|
||
| struct future_util_bench {}; | ||
|
|
||
| ss::future<> ignore_shutdown_ready() { | ||
| return ssx::ignore_shutdown_exceptions(input_ready()); | ||
| } | ||
|
|
||
| ss::future<> ignore_shutdown_gate_closed() { | ||
| return ssx::ignore_shutdown_exceptions(input_gate_closed()); | ||
| } | ||
|
|
||
| ss::future<> ignore_shutdown_abort_requested() { | ||
| return ssx::ignore_shutdown_exceptions(input_abort_requested()); | ||
| } | ||
|
|
||
| // ignore_shutdown_exceptions rethrows non-shutdown exceptions, so swallow the | ||
| // result to keep the loop running. The trailing handle_exception is common-mode | ||
| // overhead (present for any caller that handles the rethrow), so the delta | ||
| // between builds still isolates the filter/rethrow cost. | ||
| ss::future<> ignore_shutdown_non_shutdown() { | ||
| return ssx::ignore_shutdown_exceptions(input_runtime_error()) | ||
| .handle_exception([](std::exception_ptr) {}); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| PERF_TEST_F(future_util_bench, ignore_shutdown_ready) { | ||
| return co_await_in_loop(ignore_shutdown_ready); | ||
| } | ||
|
|
||
| PERF_TEST_F(future_util_bench, ignore_shutdown_gate_closed) { | ||
| return co_await_in_loop(ignore_shutdown_gate_closed); | ||
| } | ||
|
|
||
| PERF_TEST_F(future_util_bench, ignore_shutdown_abort_requested) { | ||
| return co_await_in_loop(ignore_shutdown_abort_requested); | ||
| } | ||
|
|
||
| PERF_TEST_F(future_util_bench, ignore_shutdown_non_shutdown) { | ||
| return co_await_in_loop(ignore_shutdown_non_shutdown); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.