Repository navigation
hold environments that are free to copy by value in env adaptors - #2555
Merged
Merged
Conversation
`__fwd_env`, `__join`, `__hide_query` and `__hide_scheduler` held an lvalue environment by reference and an rvalue by value, so an environment that was reachable both ways had two spellings. everything computed from the type of an environment (completion signatures, completion domains, the attributes of the operations nested in it) was computed once for each. an environment that is trivially copy-constructible and trivially destructible is now held by value either way (`__env::__held_t`). copying it costs nothing, and its adaptors have one spelling. other lvalue environments are still held by reference. on test_merge_each_threaded.cpp (clang 22, frontend only), peak memory drops from 5.5 GB to 2.9 GB with extra type checking and from 2.4 GB to 1.5 GB without, and compile time by about 40%. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
env adaptors (
__fwd_env,__join,__hide_query,__hide_scheduler) held an lvalue environment by reference and an rvalue by value, so one environment had several types:__fwd<E const&>and__fwd<E>,__hide_scheduler<E const&>and__hide_scheduler<E>, and so on. everything computed from the type of an environment (completion signatures, completion domains, the facade's walk of nested operations) was computed once for each. in test_merge_each_threaded.cpp,get_completion_signatureswas instantiated for 2340 (sender, environment) pairs, only 1228 of them distinct once the spellings are merged.now an environment that is trivially copy-constructible and trivially destructible is held by value either way (
__env::__held_t). copying it costs nothing. other lvalue environments, such as ones that hold ashared_ptr, are still held by reference. (a query that returns a reference into the environment now returns one into the adaptor's copy, as it already did when the adaptor was given an rvalue.)test_merge_each_threaded.cpp with clang 22, peak memory and time:
-O3, extra type checking)tested locally with clang 22, gcc 15, clang 16 and nvc++ 26.11. every test file also compiles with clang 22 and
STDEXEC_ENABLE_EXTRA_TYPE_CHECKING.🤖 Generated with Claude Code