perf: remove unnecessary async_trait usage#14041
Conversation
There was a problem hiding this comment.
Pull request overview
This PR removes unnecessary async_trait usage where async trait methods can use native impl Future static dispatch, reducing boxed-future overhead in compilation passes, lazy compilation helpers, persistent cache occasions, and parallel utilities.
Changes:
- Converts statically dispatched async traits (
PassExt, lazy compilationBackend/test hooks, persistent cacheOccasion) to returnimpl Future. - Replaces dynamic boxed pass sequencing with direct static pass calls.
- Removes redundant
async_traitannotations/imports and drops the unusedrspack_paralleldependency.
Reviewed changes
Copilot reviewed 34 out of 35 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
Cargo.lock |
Removes async-trait from rspack_parallel lock dependencies. |
crates/rspack_parallel/Cargo.toml |
Drops unused async-trait dependency. |
crates/rspack_parallel/src/iterator_consumer/future.rs |
Removes redundant async_trait annotations from non-async trait/impl. |
crates/rspack_plugin_lazy_compilation/src/backend.rs |
Converts Backend async API to impl Future. |
crates/rspack_plugin_lazy_compilation/src/plugin.rs |
Converts lazy compilation test hook to impl Future. |
crates/rspack_binding_api/src/raw_options/raw_builtins/raw_lazy_compilation.rs |
Removes async_trait from lazy compilation hook implementations. |
crates/rspack_core/src/compilation/pass.rs |
Converts compilation pass trait async methods to impl Future. |
crates/rspack_core/src/compilation/run_passes.rs |
Replaces boxed pass vector with direct static sequencing. |
crates/rspack_core/src/compilation/after_process_assets/mod.rs |
Removes pass async_trait usage. |
crates/rspack_core/src/compilation/after_seal/mod.rs |
Removes pass async_trait usage. |
crates/rspack_core/src/compilation/assign_runtime_ids/mod.rs |
Removes pass async_trait usage. |
crates/rspack_core/src/compilation/build_chunk_graph/pass.rs |
Removes pass async_trait usage. |
crates/rspack_core/src/compilation/build_module_graph/pass.rs |
Removes pass async_trait usage. |
crates/rspack_core/src/compilation/chunk_ids/mod.rs |
Removes pass async_trait usage. |
crates/rspack_core/src/compilation/code_generation/mod.rs |
Removes pass async_trait usage. |
crates/rspack_core/src/compilation/create_chunk_assets/mod.rs |
Removes pass async_trait usage. |
crates/rspack_core/src/compilation/create_hash/mod.rs |
Removes pass async_trait usage. |
crates/rspack_core/src/compilation/create_module_assets/mod.rs |
Removes pass async_trait usage. |
crates/rspack_core/src/compilation/create_module_hashes/mod.rs |
Removes pass async_trait usage. |
crates/rspack_core/src/compilation/finish_modules/mod.rs |
Removes pass async_trait usage. |
crates/rspack_core/src/compilation/module_ids/mod.rs |
Removes pass async_trait usage. |
crates/rspack_core/src/compilation/optimize_chunk_modules/mod.rs |
Removes pass async_trait usage. |
crates/rspack_core/src/compilation/optimize_chunks/mod.rs |
Removes pass async_trait usage. |
crates/rspack_core/src/compilation/optimize_code_generation/mod.rs |
Removes pass async_trait usage. |
crates/rspack_core/src/compilation/optimize_dependencies/mod.rs |
Removes pass async_trait usage. |
crates/rspack_core/src/compilation/optimize_modules/mod.rs |
Removes pass async_trait usage. |
crates/rspack_core/src/compilation/optimize_tree/mod.rs |
Removes pass async_trait usage. |
crates/rspack_core/src/compilation/process_assets/mod.rs |
Removes pass async_trait usage. |
crates/rspack_core/src/compilation/runtime_requirements/mod.rs |
Removes pass async_trait usage. |
crates/rspack_core/src/compilation/seal/mod.rs |
Removes pass async_trait usage. |
crates/rspack_core/src/runtime_module.rs |
Removes redundant async_trait from non-async runtime helper traits. |
crates/rspack_core/src/cache/persistent/occasion/mod.rs |
Converts Occasion::recovery to impl Future. |
crates/rspack_core/src/cache/persistent/occasion/make/mod.rs |
Removes async_trait from MakeOccasion. |
crates/rspack_core/src/cache/persistent/occasion/meta/mod.rs |
Removes async_trait from MetaOccasion. |
crates/rspack_core/src/cache/persistent/occasion/minimize/mod.rs |
Removes async_trait from MinimizeOccasion. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
📦 Binary Size-limit
❌ Size increased by 4.00KB from 61.95MB to 61.96MB (⬆️0.01%) |
Rsdoctor Bundle Diff AnalysisFound 6 projects in monorepo, 2 projects with changes. 📊 Quick Summary
📋 Detailed Reports (Click to expand)📁 popular-libsPath:
📦 Download Diff Report: popular-libs Bundle Diff 📁 ui-componentsPath:
📦 Download Diff Report: ui-components Bundle Diff Generated by Rsdoctor GitHub Action |
Merging this PR will not alter performance
Comparing Footnotes
|
|
@codspeedbot fix this regression |
The Root cause: Removing Fix: The default The change is a single 2-line edit in Summary
|
b3dc613 to
0091c3b
Compare
|
@codspeedbot fix this regression again |
Comment handling failed unexpectedly: TypeError Summary
|
|
Hey @hardfist, sorry for this error. We are fixing it right now! |
|
@codspeedbot fix this regression again |
The Root cause: Removing Fix: Kept This exact approach was already validated by CodSpeed at 690.1 µs — matching the 690.3 µs baseline. Summary
|
4624504 to
dbb193b
Compare
Summary
async_traitdispatch withimpl Futurestatic dispatch and direct pass sequencing#[async_trait]usage from static async traits and non-async runtime helper traitsasync-traitdependency fromrspack_parallelWhy
async-traitis useful when an async trait must be used throughdyndispatch, but it works by erasing each async method into a boxed future. That boxing can allocate on the heap for every call. The traits changed here are statically dispatched, or do not have async methods, so using nativeimpl Future/ plain trait methods avoids those unnecessary allocations while keepingasync_traitin places that still need object-safe async trait calls.Related Rust blog: Async fn and return-position impl Trait in traits.
Validation
cargo fmt --allcargo check -p rspack_core -p rspack_parallel -p rspack_plugin_lazy_compilation -p rspack_binding_apicargo check -p rspack_benchmark --bencheslint-stagedranrustfmtandpnpm exec taplo formatduring commit