Skip to content

hold environments that are free to copy by value in env adaptors - #2555

Merged
ericniebler merged 1 commit into
NVIDIA:mainfrom
ericniebler:one-env-spelling
Nov 27, 2026
Merged

ericniebler merged 1 commit into
NVIDIA:mainfrom
ericniebler:one-env-spelling

Conversation

@ericniebler

Copy link
Copy Markdown
Collaborator

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_signatures was 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 a shared_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:

main this PR
CI's flags (-O3, extra type checking) 5.8 GB, 138 s 3.2 GB, 78 s
frontend only, extra type checking 5.3 GB, 118 s 2.9 GB, 63 s
frontend only 2.4 GB, 49 s 1.5 GB, 30 s

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

`__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>
@ericniebler
ericniebler merged commit 5750392 into NVIDIA:main Nov 27, 2026
41 checks passed
@ericniebler
ericniebler deleted the one-env-spelling branch November 27, 2026 06:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant