Repository navigation
don't instantiate the operations below the walk states of starts_on, finally, repeat and associate - #2564
Open
ericniebler wants to merge 4 commits into
Open
don't instantiate the operations below the walk states of starts_on, finally, repeat and associate#2564ericniebler wants to merge 4 commits into
ericniebler wants to merge 4 commits into
Conversation
starts_on's state holds its child's operation, connected to the facade's receiver for the child. When the state's receiver is an archetype, as in the facade's walk, that receiver is __nested_receiver_archetype, so the walk instantiated the child's operations a second time, and, through __start_nested, their start functions. (Only a sequence sender's item source got a placeholder.) Now starts_on declares its state's type with __state_type (see NVIDIA#2562), and a state whose receiver is an archetype holds a placeholder (__walk_op) for the child's operation, and connects nothing. Whether connecting the child can throw is still asked of the real operation, which a new test checks. on(sch, sndr) is lowered to continues_on(starts_on(sch, sndr), ...), so it gains too. MAINTAINERS.md now says what a state whose receiver is an archetype does. A pipeline of a dozen algorithms (let_value, when_all, continues_on, bulk), 8.78 s alone (clang 22 -O3), in starts_on: 9.10 s / 527 MB -> 8.95 s / 507 MB, and with extra type checking 11.14 s -> 10.75 s; in on: 9.61 s -> 9.40 s. test_starts_on.cpp: 9.60 s -> 9.40 s, test_on.cpp: 11.71 s -> 11.54 s. Their GCC 15 Debug objects are 1.4% and 0.9% smaller. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
__finally_'s state holds the operations of both of its children, connected to the facade's receivers for them, which are receiver archetypes in the facade's walk. So the walk instantiated both children's operations a second time, and, through __start_nested, their start functions. affine lowers to __finally_(sndr, unstoppable(schedule(sch))) when sndr is not already affine, and task awaits every sender through affine, so each co_await of such a sender paid for this. Now __finally_ declares its state's type with __state_type, and a state whose receiver is an archetype holds placeholders for the operations, and connects nothing. Whether connecting either child can throw is still asked of the real operations, which a new test checks. The same pipeline in finally (clang 22 -O3): 9.39 s / 541 MB -> 9.19 s / 535 MB, and with extra type checking 11.41 s -> 11.02 s. test_finally.cpp: 9.16 s / 554 MB -> 8.92 s / 531 MB. Its GCC 15 Debug object is 3.3% smaller. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The state of repeat_n, repeat_until and repeat holds the operation of the current iteration's body. Its __get_state's return type was deduced, so naming the state's type instantiated __get_state's body, and with it the state's constructor, which connects the first iteration's body. And the handlers connect the body of each next iteration. So the walk instantiated the body's connect and start functions, connected to a receiver archetype. Now __get_state names its return type, __state_type: the state, or the type error that it reports. And a state whose receiver is an archetype holds a placeholder for the body's operation, and connects nothing. The walk still asks whether connecting the body can throw, which decides whether the operation can complete with set_error_t(std::exception_ptr) (test_repeat_n.cpp checks that), so it still instantiates the type of the body's operation, but none of its functions. The trampoline's operation is the same in every walk, so it stays. The same pipeline in repeat_n (clang 22 -O3): 9.91 s / 561 MB -> 9.53 s / 546 MB, and with extra type checking 13.48 s / 695 MB -> 12.06 s / 647 MB. test_repeat_n.cpp: 11.95 s -> 11.62 s, test_repeat_until.cpp: 12.25 s -> 11.93 s. Their GCC 15 Debug objects are 1.4% and 1.6% smaller. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
associate's state holds the operation of the sender that it wraps, connected to the facade's receiver for it, which is a receiver archetype in the facade's walk. So the walk instantiated the wrapped sender's operations a second time, and, through __start_nested, their start functions. Now associate declares its state's type with __state_type, and a state whose receiver is an archetype holds a placeholder for the operation, and connects nothing. Whether connecting the wrapped sender can throw is still asked of the real operation, which a new test checks. The same pipeline in associate, with a simple_counting_scope (clang 22 -O3): 9.92 s / 559 MB -> 9.10 s / 517 MB, and with extra type checking 11.73 s -> 10.67 s. test_associate.cpp: 10.36 s -> 10.24 s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
the treatment that #2563 gave fork_join, for the other algorithms whose states hold operations: starts_on (and so on), finally (and so affine, and task's co_await of a sender that is not affine), the repeating algorithms, and associate. one commit each.
a state whose receiver is an archetype, as in the facade's walk, now holds placeholders for its operations, and connects nothing. before, the walk instantiated each nested subtree a second time, connected to
__nested_receiver_archetype, and, through__start_nested, its start functions. whether connecting can throw is still asked of the real operations: new tests check that for starts_on, finally and associate (each fails if a walk state's noexcept is made unconditional), and test_repeat_n.cpp already did for repeat.clang 22 -O3, the minimum of 3 runs, compiling main's test files. the pipeline is a dozen algorithms (let_value, when_all, continues_on, bulk), which take 8.78 s alone.
gcc 15 debug objects: test_finally 3.3% smaller, test_repeat_until 1.6%, test_repeat_n 1.4%, test_starts_on 1.4%, test_on 0.9%, test_task 0.6%, test_associate 0.1%; test_let_value and test_merge_each_threaded unchanged.
tested locally: the 123 test files that need no CMake target of their own, with clang 22 and gcc 15 (-Werror), the changed tests with STDEXEC_ENABLE_EXTRA_TYPE_CHECKING, and clang-format-21. not run locally: clang 16, nvc++, cuda, msvc.
🤖 Generated with Claude Code