Repository navigation
reduce the parse time of stdexec/execution.hpp - #2592
Merged
Merged
Conversation
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>
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.
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.<execution>on libstdc++, only the policy types from<pstl/execution_defs.h>(-0.75s)<algorithm>(no timing change by itself; other headers still pull it in)__proxy_env::querya template so it doesn't instantiate__any_allocatorin every TU (-0.14s)<thread>and<stop_token>: new__this_thread.hppuses pthreads/sched_yieldon POSIX and falls back to<thread>elsewhere<bits/ranges_base.h>instead of<ranges>for the deprecatedstdexec::rangesaliases 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.stdexecandtest.execpass locally (GCC 16, Debug). i have not tested clang/libc++, windows or cuda at runtime.🤖 Generated with Claude Code