Skip to content

core: cut codex-core compile time 48% with native async SessionTask#16631

Merged
bolinfest merged 1 commit intomainfrom
pr16631
Apr 2, 2026
Merged

core: cut codex-core compile time 48% with native async SessionTask#16631
bolinfest merged 1 commit intomainfrom
pr16631

Conversation

@bolinfest
Copy link
Copy Markdown
Collaborator

@bolinfest bolinfest commented Apr 2, 2026

Why

This continues the compile-time cleanup from #16630. SessionTask implementations are monomorphized, but Session stores the task behind a dyn boundary so it can drive and abort heterogenous turn tasks uniformly. That means we can move the #[async_trait] expansion off the implementation trait, keep a small boxed adapter only at the storage boundary, and preserve the existing task lifecycle semantics while reducing the amount of generated async-trait glue in codex-core.

One measurement caveat showed up while exploring this: a warm incremental benchmark based on touch core/src/tasks/mod.rs && cargo check -p codex-core --lib was basically flat, but that was the wrong benchmark for this change. Using package-clean codex-core rebuilds, like #16630, shows the real win.

Relevant pre-change code:

What changed

  • Switched SessionTask::{run, abort} to native RPITIT futures with explicit Send bounds.
  • Added a private AnySessionTask adapter that boxes those futures only at the Arc<dyn ...> storage boundary.
  • Updated RunningTask to store Arc<dyn AnySessionTask> and removed #[async_trait] from the concrete task impls plus test-only SessionTask impls.

Timing

Benchmarked package-clean codex-core rebuilds with dependencies left warm:

cargo check -p codex-core --lib >/dev/null
cargo clean -p codex-core >/dev/null
/usr/bin/time -p cargo +nightly rustc -p codex-core --lib -- \
  -Z time-passes \
  -Z time-passes-format=json >/dev/null
revision rustc total process real generate_crate_metadata MIR_borrow_checking monomorphization_collector_graph_walk
parent 3c7f013f9735 67.21s 67.71s 24.61s 23.43s 22.43s
this PR 2cafd783ac22 35.08s 35.60s 8.01s 7.25s 7.15s
delta -47.8% -47.4% -67.5% -69.1% -68.1%

For completeness, the warm touched-file benchmark stayed flat (1.96s parent vs 1.97s this PR), which is why that benchmark should not be used to evaluate this refactor.

Verification

  • Ran cargo test -p codex-core; this change compiled and task-related tests passed before hitting the same unrelated 5 config::tests::*guardian* failures already present on the parent stack.

@bolinfest bolinfest changed the title core: use native async SessionTask trait core: cut codex-core compile time 48% with native async SessionTask Apr 2, 2026
@bolinfest bolinfest requested a review from aibrahim-oai April 2, 2026 23:36
@bolinfest bolinfest enabled auto-merge (squash) April 2, 2026 23:39
@bolinfest bolinfest merged commit 7a3eec6 into main Apr 2, 2026
28 of 30 checks passed
@bolinfest bolinfest deleted the pr16631 branch April 2, 2026 23:39
@github-actions github-actions bot locked and limited conversation to collaborators Apr 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants