perf(coro): share direct-await execution contexts - #1035
Conversation
There was a problem hiding this comment.
Pull request overview
Optimizes direct coroutine composition by sharing execution contexts while preserving isolation at runtime and structured-cancellation boundaries.
Changes:
- Defers and shares contexts for direct Elio task awaits.
- Preserves independent contexts for spawning, foreign promises, and
task_scope(). - Adds regression tests, benchmarks, and migration documentation.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
CHANGELOG.md |
Documents the breaking context semantics. |
examples/microbench.cpp |
Benchmarks direct-await chains. |
include/elio/coro/promise_base.hpp |
Implements deferred context binding and isolation. |
include/elio/coro/task.hpp |
Shares contexts across direct awaits. |
include/elio/coro/task_execution_context.hpp |
Updates logical-vthread context behavior. |
include/elio/coro/task_group.hpp |
Isolates task_scope() contexts. |
include/elio/runtime/scheduler.hpp |
Materializes contexts during scheduler admission. |
include/elio/runtime/spawn.hpp |
Materializes contexts for spawn failures. |
tests/unit/test_io.cpp |
Adapts raw-resume I/O coverage. |
tests/unit/test_task_execution_context.cpp |
Tests sharing, allocation, and ownership. |
tests/unit/test_task_group.cpp |
Tests scope cancellation isolation. |
wiki/API-Contracts.md |
Updates public behavioral contracts. |
wiki/API-Reference.md |
Documents context and scope semantics. |
wiki/Core-Concepts.md |
Explains logical-vthread context sharing. |
wiki/Migrating-to-0.6.md |
Provides migration guidance. |
wiki/Performance-Tuning.md |
Describes allocation improvements. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
@copilot Please review the current PR head only. Do not make code changes. |
Review of current PR head (commits SummaryThe two commits together correctly implement context sharing for direct-await chains and address the original frame-ownership safety concern on context-materialization failure. The following is a read-only assessment of the current head.
|
Description
Share one
task_execution_contextacross ordinary directly awaited Elio taskframes, so transparent coroutine composition no longer allocates a context and
parent-cancellation callback per frame. The actual first await or runtime
handoff is authoritative; task creation ancestry is not.
task_scope()remains an explicit structured-cancellation boundary. Callercancellation propagates into it, scope cancellation does not poison its caller
after join, and the final user-affinity value flows back without transferring
active I/O pins.
Type of Change
Related Issues
Closes #1034
Related to #1032
Changes Made
Core Changes
transparent children to the actual Elio awaiter's context.
keep raw
try_spawnownership safe if materialization throws.copy-back bookkeeping.
task_scope()isolation with one-way parent cancellation and finaluser-affinity propagation.
regressions, raw-resume coverage, and documentation across the API contract,
reference, concepts, migration, performance, and changelog pages.
API Changes
Before: each directly awaited Elio task frame owned a distinct execution
context, linked cancellation from its parent, and copied affinity at await
boundaries.
After: ordinary directly awaited Elio frames share the logical-vthread root
context. Independent roots, foreign promises, and
task_scope()use distinctcontexts.
Migration Guide
Use
spawn()/go()when a helper requires a distinct cancellation or affinitydomain. A token retained from a completed transparent child now names the
surrounding logical vthread. Low-level integrations that inspect or raw-resume
a nested unstarted task must first materialize an independent context; normal
task awaits and runtime handoffs do this automatically.
Testing
Unit Tests
Integration Tests
Sanitizer Testing
Test Results
Pinned Release direct-await benchmark, five interleaved baseline/current pairs:
Checklist
Code Quality
Documentation
Testing
Compatibility
Performance
Additional Notes
The common transparent direct-await path still contains no new allocation. A
rare raw-resumed deferred root materializes its context on the first nested
direct await to preserve low-level safety.
Reviewer Guidance
Areas requiring special attention:
task-group, foreign-promise, and raw-handle paths.
task_scope()cancellation isolation versus parent propagation and affinitycontinuity.
Questions for reviewers:
task_scope()exception to transparent sharing sufficiently explicitin code and documentation?