Skip to content

reduce the parse time of stdexec/execution.hpp - #2592

Merged
ericniebler merged 10 commits into
NVIDIA:mainfrom
ericniebler:reduce-header-parse-time
Dec 1, 2026
Merged

ericniebler merged 10 commits into
NVIDIA:mainfrom
ericniebler:reduce-header-parse-time

Conversation

@ericniebler

Copy link
Copy Markdown
Collaborator

parsing <stdexec/execution.hpp> took about 2.0s with GCC 15 (libstdc++, no CCCL); it now takes about 1.05s. clang 22 goes from 1.80s to 1.57s.

  • don't include <execution> on libstdc++, only the policy types from <pstl/execution_defs.h> (-0.75s)
  • stop including <algorithm> (no timing change by itself; other headers still pull it in)
  • make __proxy_env::query a template so it doesn't instantiate __any_allocator in every TU (-0.14s)
  • stop including <thread> and <stop_token>: new __this_thread.hpp uses pthreads/sched_yield on POSIX and falls back to <thread> elsewhere
  • use <bits/ranges_base.h> instead of <ranges> for the deprecated stdexec::ranges aliases on libstdc++

user code that relied on <stdexec/execution.hpp> to bring in <execution>, <stop_token> or <thread> must now include them. two tests needed that fix.

test.stdexec and test.exec pass locally (GCC 16, Debug). i have not tested clang/libc++, windows or cuda at runtime.

🤖 Generated with Claude Code

ericniebler and others added 10 commits November 30, 2026 15:53
libstdc++'s <execution> pulls in the whole parallel-algorithms machinery, costing about 0.75s of the 2.0s it takes to parse <stdexec/execution.hpp> with GCC 15. We need only the policy types and objects, which live in <pstl/execution_defs.h> (24ms). Import them from ::__pstl::execution when that header exists. The types are identical to std::execution's, so user code that includes <execution> itself sees no difference.

Code that relied on <stdexec/execution.hpp> to bring in <execution> transitively must now include it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Replace std::ranges::sort in __msort_impl with a constexpr heapsort, std::copy/std::min/std::ranges::copy_n in __static_vector with plain loops, and std::max in the parallel scheduler with the existing __umax. The last one had been relying on a transitive include. No measurable parse-time change on its own, since other standard headers pull <algorithm> in anyway, but it removes the dependency.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
__proxy_env::query(get_allocator_t) was a non-template inline function, so its body was compiled in every TU that includes the header, instantiating the __any type-erasure machinery (about 200ms with clang). Make it a template so the body is instantiated only on use.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
In C++20 libstdc++'s <thread> includes <stop_token>, <semaphore>, <ostream>, <ios> and <locale>. stdexec used <thread> only for thread ids and yield, so add __this_thread.hpp, which uses pthread_self/pthread_equal/sched_yield on POSIX and falls back to <thread> elsewhere. Also drop the <stop_token> include: the existing forward declarations of std::stop_token and std::stop_callback suffice for the specializations.

Fix two tests that relied on those transitive includes. User code that used std::stop_token or std::thread without including their headers will need to.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…bstdc++

<ranges> costs about 0.28s of parse time on libstdc++. The deprecated aliases need only what <bits/ranges_base.h> defines (71ms).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The non-libstdc++ branch imported is_execution_policy and is_execution_policy_v from std::execution, but the standard declares them in namespace std (MSVC and nvc++ rejected it). Only libstdc++'s __pstl::execution has them.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
inplace_stop_source lives in STDEXEC_P2300_NAMESPACE, which can be std::execution, so __this_thread:: must be spelled STDEXEC::__this_thread::. Relacy redefines pthread_t and needs its atomics' values to be streamable, so add STDEXEC_DISABLE_POSIX_THREAD_ID, which selects std::thread::id, and define it for the Relacy tests.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
timed_thread_scheduler.hpp uses std::thread, and several tests use std::stop_source, without including their headers; maxwell/stdpar.cuh runs the standard algorithms with execution policies and needs <execution>. All of these had relied on <stdexec/execution.hpp> including them. Guard <stop_token> with __has_include, as stdexec did, since clang 16's library lacks it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
__any_allocator's nested __alloc_impl derived from the non-dependent __any<__byte_allocator>, which was instantiated, with its whole interface hierarchy, when the template was defined. Derive from a dependent alias instead. Two non-template uses forced it again: __proxy_env::query's return type and __receiver_proxy_base::__query's use of __mtypeid<__any_allocator<std::byte>>; make both take the allocator type as a defaulted template parameter. Saves about 0.12s of 1.57s with clang 22; test.stdexec and test.exec pass.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@ericniebler
ericniebler merged commit 12259a1 into NVIDIA:main Dec 1, 2026
53 of 54 checks passed
@ericniebler
ericniebler deleted the reduce-header-parse-time branch December 1, 2026 03:47
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