perf: replace trivial async implementations with ready - #654
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Console::send now performs stdout I/O eagerly at call time via ready((|| { ... })()), which changes Future laziness semantics and can trigger side effects even if the future is dropped without being polled.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR refactors several trivial async implementations into regular functions that return immediately-ready futures, primarily to eliminate clippy::unused_async_trait_impl suppressions and reduce overhead in hot paths while preserving existing APIs (notably using poll_fn for Path/UrlQuery to avoid tightening Send bounds).
Changes:
- Replaced trivial
async fnextractor/handler implementations withfn ... -> impl Futurereturningcore::future::ready(...). - Updated core extractors (
Request,RequestHead,Method, etc.) and generatedFromRequestHeadderives to avoid unused-async lints (including a special-case for empty structs). - Used
core::future::poll_fnforPathandUrlQueryto keep first-poll completion without introducing extraSendrequirements on deserialized outputs.
File summaries
| File | Description |
|---|---|
| cot/tests/from_request.rs | Updates test extractor impl to return an immediately-ready future instead of a trivial async fn. |
| cot/src/router.rs | Refactors test RequestHandler impl to return a ready future and removes lint suppression. |
| cot/src/request/extractors.rs | Converts several built-in FromRequestHead impls to ready(...)-based futures. |
| cot/src/project.rs | Changes Bootstrapper<WithCache>::boot from async fn to returning a ready future and removes lint expectations. |
| cot/src/error/handler.rs | Refactors error extractors to return immediately-ready futures instead of trivial async fns. |
| cot/src/email/transport/console.rs | Converts console email transport send to a ready-future implementation. |
| cot/src/db/impl_postgres.rs | Changes a trivial async init method to return a ready future and adjusts clippy expectations. |
| cot/src/db/impl_mysql.rs | Same as postgres: replaces trivial async init with ready future and updates clippy expectations. |
| cot/src/cache.rs | Refactors Cache::from_config to return an immediately-ready future instead of an async fn. |
| cot/src/admin.rs | Converts AdminModelManagers extractor to return a ready future. |
| cot-macros/src/from_request.rs | Updates derive output to use ready(...) for empty structs while keeping async generation for non-empty ones. |
| cot-core/src/request/extractors.rs | Updates core extractor impls and uses poll_fn for Path/UrlQuery to preserve generic bounds. |
Review details
- Files reviewed: 12/12 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report❌ Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
The Clippy job exposed one additional conditional |
|
GitHub could not reopen this PR after the deleted fork was recreated because the PR retains the old repository ID. The exact head commit is restored in replacement PR #655. |
Related issue or discussion
Fixes #651
Description
Replaces trivial
asyncimplementations with regular functions returning immediately-ready futures, removing theunused_async_trait_implsuppressions from production code and generated empty extractors.PathandUrlQueryusepoll_fnrather thanready: storing their result inReadywould add aSendrequirement to the deserialized output and narrow the existing generic API. The console transport also usespoll_fnso its stdout side effects remain lazy. Each computation still completes on the first poll without an async state machine.Type of change
Checklist
just test-all) — the full non-ignored workspace and doctest suite passes; ignored service tests could not start because local port 5432 is occupiedjust clippy)cargo fmt)Commands run
cargo test --workspace --all-featurescargo clippy --workspace --all-targets --all-features -- -D warningscargo fmt --check