Skip to content

perf: replace trivial async implementations with ready - #655

Open
anishfyi wants to merge 5 commits into
cot-rs:masterfrom
anishfyi:fix-651-ready-futures
Open

perf: replace trivial async implementations with ready#655
anishfyi wants to merge 5 commits into
cot-rs:masterfrom
anishfyi:fix-651-ready-futures

Conversation

@anishfyi

@anishfyi anishfyi commented Aug 31, 2026

Copy link
Copy Markdown

Replaces #654, which GitHub closed automatically when its head fork was accidentally deleted. This branch restores the exact reviewed commit.

Related issue or discussion

Fixes #651

Description

Replaces trivial async implementations with regular functions returning immediately-ready futures, removing the unused_async_trait_impl suppressions from production code and generated empty extractors.

Path and UrlQuery use poll_fn rather than ready: storing their result in Ready would add a Send requirement to the deserialized output and narrow the existing generic API. The console transport also uses poll_fn so its stdout side effects remain lazy. Each computation still completes on the first poll without an async state machine.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Refactor / cleanup
  • Performance improvement
  • Other (describe above)

Checklist

  • I've read the contributing guide
  • Tests pass locally (just test-all) — the full non-ignored workspace and doctest suite passes; ignored service tests could not start because local port 5432 is occupied
  • Code passes clippy (just clippy)
  • Code is properly formatted (cargo fmt)
  • New tests added (not applicable: behavior is unchanged and existing extractor/derive tests cover the changed paths)
  • Documentation updated (not applicable: no user-facing behavior changed)

Commands run

  • cargo test --workspace --all-features
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo fmt --check

Copilot AI lite review requested due to automatic review settings August 31, 2026 16:14
@github-actions github-actions Bot added C-lib Crate: cot (main library crate) C-macros Crate: cot-macros C-core labels Aug 31, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Cache::from_config now eagerly performs work at call time via ready(...), which changes the laziness/side-effect timing compared to the prior async fn behavior.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR refactors several trivial async fn implementations into synchronous functions that return immediately-ready futures (or poll_fn where needed), with the goal of removing unused_async_trait_impl suppressions and reducing async state-machine overhead across the Cot workspace.

Changes:

  • Replaced trivial async trait method impls with fn ... -> impl Future<...> returning core::future::ready(...) in multiple extractors/handlers.
  • Used core::future::poll_fn(...) for cases where ready(...) would impose additional Send constraints or where side effects should remain lazy (e.g., Path, UrlQuery, console email transport).
  • Updated cot-macros derive output to generate a non-async ready future for empty FromRequestHead structs.
File summaries
File Description
cot/tests/from_request.rs Updates a test extractor impl to return an immediately-ready future instead of async fn.
cot/src/router.rs Updates a test RequestHandler impl to return a ready future and removes the clippy suppression.
cot/src/request/extractors.rs Converts several built-in extractor impls to return ready futures instead of trivial async.
cot/src/project.rs Refactors bootstrapper cache setup/boot APIs to return futures without trivial async fn wrappers.
cot/src/error/handler.rs Converts error extractors to return ready futures rather than trivial async fn.
cot/src/email/transport/console.rs Converts console transport send to use poll_fn to keep stdout side effects lazy.
cot/src/db/impl_postgres.rs Replaces a trivial async init with a ready future and updates clippy expectations accordingly.
cot/src/db/impl_mysql.rs Replaces a trivial async init with a ready future and updates clippy expectations accordingly.
cot/src/cache.rs Converts Cache::from_config to return a ready future (now eager at call time).
cot/src/admin.rs Converts AdminModelManagers extractor impl to return a ready future.
cot-macros/src/from_request.rs Emits a ready-future implementation for empty structs derived with FromRequestHead.
cot-core/src/request/extractors.rs Refactors core extractors to ready futures, using poll_fn for Path/UrlQuery to avoid extra Send constraints.
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.

Comment thread cot/src/cache.rs Outdated
Defer cache store selection until the returned future is polled, matching the behavior of the previous async function.
@anishfyi

Copy link
Copy Markdown
Author

I found and fixed one more laziness regression during a follow-up audit. Bootstrapper<WithCache>::boot now defers middleware and auth backend setup until the returned future is polled, matching the former async fn behavior. The new bootstrapper_with_cache_boot_is_lazy regression test, 16 focused project tests, all-features Clippy with warnings denied, formatting, and git diff --check pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-core C-lib Crate: cot (main library crate) C-macros Crate: cot-macros

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use core::future::ready instead of #[expect(clippy::unused_async_trait_impl)]

2 participants