Skip to content

Add inplace_stoppable_base to reduce operation state sizes - #2413

Merged
ericniebler merged 17 commits into
NVIDIA:mainfrom
vasama:inplace_stoppable_base
Nov 5, 2026
Merged

ericniebler merged 17 commits into
NVIDIA:mainfrom
vasama:inplace_stoppable_base

Conversation

@vasama

@vasama vasama commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Introduction

This PR introduces a CRTP alternative to stop callbacks. This allows reducing the sizes of many operation states for two reasons:

  1. __optional wrappers can be eliminated, because the stoppable base tracks its own state.
  2. Pointers to the operation states stored in their stop callbacks can be eliminated, because a reference to the operation state can be derived from a reference to the stop callback base.

See also P3301: inplace_stoppable_base.

Changes in this PR

  • A concrete implementation for inplace_stop_token: inplace_stoppable_base
  • A generic implementation based on stop callbacks.
  • stoppable_base_for_t alias template, analogous to stop_callback_for_t.

Measurements

This table shows sizes of operation state objects, using three different stop token types, before and after the changes. Measured on x86-64 Ubuntu 26.04 using Clang 22.

Operation state inplace_stop_token std::stop_token never_stop_token
when_all 120 → 104 136 80 → 72
when_any 120 → 104 136 72
split 88 → 72 104 40
ensure_started 88 → 72 104 40
merge_each 80 → 64 96 40 → 32
async_scope future operation 80 → 64 96 40 → 32
async_scope future state (heap) 224 → 208 (always inplace) – –
timed_thread_scheduler schedule_after 192 → 176 208 144
io_uring schedule_after 184 → 152 200 → 184 144 → 120

Note

Similar changes were made to a few Windows or CUDA specific components, but changes in the relevant operation state sizes were not measured.

@copy-pr-bot

copy-pr-bot Bot commented Nov 5, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@vasama
vasama force-pushed the inplace_stoppable_base branch from af95622 to a874904 Compare November 5, 2026 10:02
@vasama
vasama force-pushed the inplace_stoppable_base branch 2 times, most recently from 8f8b63b to c4965c6 Compare November 5, 2026 10:05
@vasama
vasama force-pushed the inplace_stoppable_base branch from c4965c6 to 6688192 Compare November 5, 2026 11:52

@ericniebler ericniebler left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is great! thanks!

@ericniebler

Copy link
Copy Markdown
Collaborator

/ok to test 6688192

@ericniebler
ericniebler merged commit 94fe901 into NVIDIA:main Nov 5, 2026
40 checks passed
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.

2 participants