Conversation
aibrahim-oai
approved these changes
Apr 2, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Why
ToolHandlerwas still paying a large compile-time tax from#[async_trait]on every concrete handler impl, even though the only object-safe boundary the registry actually stores is the internalAnyToolHandleradapter.This PR removes that macro-generated async wrapper layer from concrete
ToolHandlerimpls while keeping the existing object-safe shim inAnyToolHandler. In practice, that gets essentially the same compile-time win as the larger type-erasure refactor in #16627, but with a much smaller diff and without changing the public shape ofToolHandler<Output = T>.That tradeoff matters here because this is a broad
codex-corehotspot and reviewers should be able to judge the compile-time impact from hard numbers, not vibes.Headline result
On a clean
codex-corepackage rebuild (cargo clean -p codex-corebefore each command), rustctotaldropped from 187.15s to 68.98s versus the shared0bd31dc382bdbaseline: -63.1%.The biggest hot passes dropped by roughly 71-72%:
0bd31dc382bd41f7ac0adeactotalgenerate_crate_metadataMIR_borrow_checkingmonomorphization_collector_graph_walkevaluate_obligationself-timeImportant caveat:
-Z time-passestimings are nested, sogenerate_crate_metadataandmonomorphization_collector_graph_walkare mostly overlapping, not additive.Why this PR over #16627
#16627 already proved that the
ToolHandlerstack was the right hotspot, but it got there by makingToolHandlerobject-safe and changing every handler to returnBoxFuture<Result<AnyToolResult, _>>directly.This PR keeps the lower-churn shape:
ToolHandlerremains generic overtype Output.Sendbounds.AnyToolHandlerremains the only object-safe adapter and still does the boxing at the registry boundary, as before.The measurements are at least comparable, and in this run this PR is slightly faster than #16627 on the pass-level total:
totalgenerate_crate_metadatamonomorphization_collector_graph_walkevaluate_obligationself-timeProfile data
Crate-level timings
cargo +nightly build -p codex-core --lib -Z unstable-options --timings=jsonaftercargo clean -p codex-core.Baseline data below is reused from the shared parent
0bd31dc382bdprofile because this PR and #16627 are both one commit on top of that same parent.durationdurationrmeta_timermeta_timecodex_corestarlarkPass-level timings
cargo +nightly rustc -p codex-core --lib -- -Z time-passes -Z time-passes-format=jsonaftercargo clean -p codex-core.totalgenerate_crate_metadataMIR_borrow_checkingmonomorphization_collector_graph_walkcodegen_cratetype_check_cratecoherence_checkingreal/user/sysSelf-profile query summary
cargo +nightly rustc -p codex-core --lib -- -Z self-profile=... -Z self-profile-events=default,query-keys,args,llvm,artifact-sizesaftercargo clean -p codex-core, summarized withmeasureme summarize -p 0.5.evaluate_obligationmir_borrowcktypeckLLVM_module_codegen_emit_objLLVM_passescodegen_moduleitems_of_instancetype_op_prove_predicateevaluate_obligation% of total CPUreal/user/sysArtifact sizes
From the same
measureme summarizeoutput:crate_metadatadep_graphlinked_artifactobject_filequery_cachecgu_instructionscodegen_unit_size_estimatework_product_indexBaseline hotspots before this change
These are the top normalized obligation buckets from the shared baseline profile:
outlives:tasks::review::ReviewTaskoutlives:tools::handlers::unified_exec::UnifiedExecHandlertrait:T as tools::registry::ToolHandleroutlives:tools::handlers::shell::ShellHandleroutlives:tools::handlers::shell::ShellCommandHandleroutlives:tools::runtimes::shell::unix_escalation::CoreShellActionProvideroutlives:tools::handlers::mcp::McpHandleroutlives:tasks::regular::RegularTaskTop
items_of_instanceentries before this change were mostly concrete async handler/task impls:tasks::regular::{impl#2}::runtools::handlers::mcp::{impl#0}::handletools::runtimes::shell::unix_escalation::{impl#2}::determine_actiontools::handlers::agent_jobs::{impl#11}::handletools::handlers::multi_agents::spawn::{impl#1}::handletasks::review::{impl#4}::runtools::handlers::multi_agents_v2::spawn::{impl#2}::handletools::handlers::multi_agents::resume_agent::{impl#1}::handletools::handlers::unified_exec::{impl#2}::handletasks::compact::{impl#4}::runWhat changed
Relevant pre-change registry shape:
codex-rs/core/src/tools/registry.rsCurrent registry shape in this PR:
codex-rs/core/src/tools/registry.rsToolHandler::{is_mutating, handle}now return nativeimpl Future + Sendfutures instead of using#[async_trait].AnyToolHandlerremains the object-safe adapter and boxes those futures at the registry boundary with explicit lifetimes.#[async_trait]but otherwise keep their async method bodies intact.codex-rs/core/src/tools/handlers/shell.rs,codex-rs/core/src/tools/handlers/unified_exec.rs,codex-rs/core/src/tools/registry_tests.rsTradeoff
This is intentionally less invasive than #16627: it does not move result boxing into every concrete handler and does not change
ToolHandlerinto an object-safe trait.Instead, it keeps the existing registry-level type-erasure boundary and only removes the macro-generated async wrapper layer from concrete impls. So the runtime boxing story stays basically the same as before, while the compile-time savings are still large.
Verification
Existing verification for this branch still applies:
cargo test -p codex-core; this change compiled and the suite reached the known unrelatedconfig::tests::*guardian*failures, with no local diff undercodex-rs/core/src/config/.Profiling commands used for the tables above:
cargo clean -p codex-corecargo +nightly build -p codex-core --lib -Z unstable-options --timings=jsoncargo +nightly rustc -p codex-core --lib -- -Z time-passes -Z time-passes-format=jsoncargo +nightly rustc -p codex-core --lib -- -Z self-profile=... -Z self-profile-events=default,query-keys,args,llvm,artifact-sizesmeasureme summarize -p 0.5