Skip to content

feat(io_context): concurrency_hint heuristic and single_threaded tie-up#242

Merged
mvandeberg merged 1 commit intocppalliance:developfrom
mvandeberg:pr/concurrency-hint-defaults
May 6, 2026
Merged

feat(io_context): concurrency_hint heuristic and single_threaded tie-up#242
mvandeberg merged 1 commit intocppalliance:developfrom
mvandeberg:pr/concurrency-hint-defaults

Conversation

@mvandeberg
Copy link
Copy Markdown
Contributor

Two related improvements to io_context construction:

  1. Static heuristic for inline budget defaults: when concurrency_hint

    1 and the user has not customized budget options, override
    (init, max, unassisted) to (0, 0, 0). Multi-thread workloads benefit from cross-thread work-stealing, which "post everything" enables; single-thread keeps the (2, 16, 4) chaining defaults.

  2. Tie concurrency_hint == 1 to single_threaded mode (asio precedent): constructing an io_context with concurrency_hint == 1 now forces opts.single_threaded = true, eliminating scheduler locking on the hot path. Matches asio's one_thread_ behavior. To opt out, pass concurrency_hint > 1.

Supporting changes:

  • reactor_scheduler: short-circuit try_consume_inline_budget and reset_inline_budget when inline_budget_max_ == 0 so post-everything mode skips TLS-list walks; relax configure_reactor validation to allow budget_max == 0; fix max(1, x) * 2 in ramp-up to escape zero.
  • io_context: apply_options_pre_/post_ now take concurrency_hint; new private configure_single_threaded_() helper used by the bare-hint and template no-opts constructors.
  • docs: update 4c2.configuration.adoc and io_context_options field docs to describe the queue-empty gating and new defaults.

Benchmark Results

Results are statistically neutral for corosio_bench.

evpp

config develop HEAD delta
1024 / 10 / 1 141.42 144.32 🏆 +2.1%
1024 / 10 / 4 438.69 471.50 🏆 +7.5%
1024 / 100 / 1 147.36 148.65 +0.9%
1024 / 100 / 4 474.55 505.09 🏆 +6.4%
4096 / 10 / 1 526.14 529.84 +0.7%
4096 / 10 / 4 1569.06 1663.34 🏆 +6.0%
4096 / 100 / 1 519.29 527.87 🏆 +1.7%
4096 / 100 / 4 1716.81 1831.97 🏆 +6.7%
16384 / 10 / 1 1683.25 1681.38 −0.1%
16384 / 10 / 4 4613.24 4675.90 🏆 +1.4%
16384 / 100 / 1 1654.33 1681.86 🏆 +1.7%
16384 / 100 / 4 5039.05 5191.18 🏆 +3.0%
1024 / 100 / 16 711.83 837.31 🏆 +17.6%
1024 / 1000 / 16 745.45 837.28 🏆 +12.3%
4096 / 100 / 16 2549.42 2905.38 🏆 +14.0%
4096 / 1000 / 16 2729.30 2872.61 🏆 +5.3%
16384 / 100 / 16 6601.52 6868.91 🏆 +4.1%
16384 / 1000 / 16 6059.62 6014.67 −0.7%
1024 / 1000 / 1 148.58 148.15 −0.3%
1024 / 1000 / 4 494.45 527.01 🏆 +6.6%
4096 / 1000 / 1 496.57 502.11 🏆 +1.1%
4096 / 1000 / 4 1773.26 1873.82 🏆 +5.7%
16384 / 1000 / 1 1595.20 1620.16 🏆 +1.6%
16384 / 1000 / 4 4698.05 4775.52 🏆 +1.6%

Summary: 19 wins, 5 ties, 0 losses (±1% threshold).

@cppalliance-bot
Copy link
Copy Markdown

cppalliance-bot commented May 5, 2026

An automated preview of the documentation is available at https://242.corosio.prtest3.cppalliance.org/index.html

If more commits are pushed to the pull request, the docs will rebuild at the same URL.

2026-05-06 00:05:47 UTC

@cppalliance-bot
Copy link
Copy Markdown

cppalliance-bot commented May 5, 2026

GCOVR code coverage report https://242.corosio.prtest3.cppalliance.org/gcovr/index.html
LCOV code coverage report https://242.corosio.prtest3.cppalliance.org/genhtml/index.html
Coverage Diff Report https://242.corosio.prtest3.cppalliance.org/diff-report/index.html

Build time: 2026-05-06 00:11:25 UTC

@codecov
Copy link
Copy Markdown

codecov Bot commented May 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.71%. Comparing base (a58ffdb) to head (b002c0e).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #242   +/-   ##
========================================
  Coverage    77.71%   77.71%           
========================================
  Files           96       96           
  Lines         7298     7298           
  Branches      1787     1787           
========================================
  Hits          5672     5672           
  Misses        1108     1108           
  Partials       518      518           
Files with missing lines Coverage Δ
include/boost/corosio/io_context.hpp 95.52% <ø> (ø)
src/corosio/src/io_context.cpp 95.83% <ø> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a58ffdb...b002c0e. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Two related improvements to io_context construction:

1. Static heuristic for inline budget defaults: when concurrency_hint
   > 1 and the user has not customized budget options, override
   (init, max, unassisted) to (0, 0, 0). Multi-thread workloads
   benefit from cross-thread work-stealing, which "post everything"
   enables; single-thread keeps the (2, 16, 4) chaining defaults.

2. Tie concurrency_hint == 1 to single_threaded mode (asio precedent):
   constructing an io_context with concurrency_hint == 1 now forces
   opts.single_threaded = true, eliminating scheduler locking on the
   hot path. Matches asio's one_thread_ behavior. To opt out, pass
   concurrency_hint > 1.

Supporting changes:
  - reactor_scheduler: short-circuit try_consume_inline_budget and
    reset_inline_budget when inline_budget_max_ == 0 so post-everything
    mode skips TLS-list walks; relax configure_reactor validation to
    allow budget_max == 0; fix max(1, x) * 2 in ramp-up to escape zero.
  - io_context: apply_options_pre_/post_ now take concurrency_hint;
    new private configure_single_threaded_() helper used by the
    bare-hint and template no-opts constructors.
  - docs: update 4c2.configuration.adoc and io_context_options field
    docs to describe the queue-empty gating and new defaults.
@mvandeberg mvandeberg force-pushed the pr/concurrency-hint-defaults branch from 15302f5 to b002c0e Compare May 5, 2026 23:58
@mvandeberg mvandeberg merged commit cd19108 into cppalliance:develop May 6, 2026
42 checks passed
@mvandeberg mvandeberg deleted the pr/concurrency-hint-defaults branch May 6, 2026 15:55
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