Skip to content

Commit c050e8f

Browse files
perf: remove unnecessary async_trait usage (#14041)
* perf: remove unnecessary async_trait usage * perf: keep async_trait for compilation passes * perf: restore impl Future for PassExt with boxed run_pass future * perf: keep async_trait on PassExt to preserve cache locality --------- Co-authored-by: codspeed-hq[bot] <117304815+codspeed-hq[bot]@users.noreply.github.com>
1 parent a65509a commit c050e8f

11 files changed

Lines changed: 14 additions & 21 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/rspack_binding_api/src/raw_options/raw_builtins/raw_lazy_compilation.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ pub struct LazyCompilationTestFn {
4242
tsfn: ThreadsafeFunction<ModuleObject, Option<bool>>,
4343
}
4444

45-
#[async_trait::async_trait]
4645
impl LazyCompilationTestCheck for LazyCompilationTestFn {
4746
async fn test(
4847
&self,
@@ -112,7 +111,6 @@ impl From<&RawLazyCompilationOption> for JsBackend {
112111
}
113112
}
114113

115-
#[async_trait::async_trait]
116114
impl Backend for JsBackend {
117115
async fn current_active_modules(&mut self) -> rspack_error::Result<IdentifierSet> {
118116
let active_modules = self

crates/rspack_core/src/cache/persistent/occasion/make/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ impl MakeOccasion {
3030
}
3131
}
3232

33-
#[async_trait::async_trait]
3433
impl Occasion for MakeOccasion {
3534
type Artifact = BuildModuleGraphArtifact;
3635

crates/rspack_core/src/cache/persistent/occasion/meta/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ impl MetaOccasion {
2929
}
3030
}
3131

32-
#[async_trait::async_trait]
3332
impl Occasion for MetaOccasion {
3433
/// Meta has no structured artifact: it reads/writes a single global counter.
3534
type Artifact = ();

crates/rspack_core/src/cache/persistent/occasion/minimize/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ impl MinimizeOccasion {
8888
}
8989
}
9090

91-
#[async_trait::async_trait]
9291
impl Occasion for MinimizeOccasion {
9392
type Artifact = MinimizePersistentCacheArtifact;
9493

crates/rspack_core/src/cache/persistent/occasion/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ pub mod make;
22
pub mod meta;
33
pub mod minimize;
44

5+
use std::future::Future;
6+
57
pub use make::MakeOccasion;
68
pub use meta::MetaOccasion;
79
pub use minimize::{
@@ -20,7 +22,6 @@ use super::storage::Storage;
2022
///
2123
/// `BuildDeps` and `Snapshot` are not occasions: they operate across multiple
2224
/// scopes and have more complex lifecycle semantics.
23-
#[async_trait::async_trait]
2425
pub trait Occasion {
2526
/// The data produced/consumed by this occasion.
2627
type Artifact: Send;
@@ -35,5 +36,8 @@ pub trait Occasion {
3536
fn save(&self, storage: &mut dyn Storage, artifact: &Self::Artifact);
3637

3738
/// Load and reconstruct the artifact from storage.
38-
async fn recovery(&self, storage: &dyn Storage) -> Result<Self::Artifact>;
39+
fn recovery<'a>(
40+
&'a self,
41+
storage: &'a dyn Storage,
42+
) -> impl Future<Output = Result<Self::Artifact>> + Send + 'a;
3943
}

crates/rspack_core/src/runtime_module.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,14 @@ pub trait RuntimeModule:
5252
}
5353
}
5454

55-
#[async_trait]
5655
pub trait AttachableRuntimeModule {
5756
fn attach(&mut self, chunk: ChunkUkey);
5857
}
5958

60-
#[async_trait]
6159
pub trait NamedRuntimeModule {
6260
fn name(&self) -> Identifier;
6361
}
6462

65-
#[async_trait]
6663
pub trait CustomSourceRuntimeModule {
6764
fn set_custom_source(&mut self, source: String);
6865
fn get_custom_source(&self) -> Option<String>;

crates/rspack_parallel/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ repository = "https://github.com/web-infra-dev/rspack"
77
version.workspace = true
88

99
[dependencies]
10-
async-trait = { workspace = true }
1110
rayon = { workspace = true }
1211
rspack_tasks = { workspace = true }
1312
tokio = { workspace = true, features = ["rt", "sync", "macros"] }

crates/rspack_parallel/src/iterator_consumer/future.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rspack_tasks::spawn_in_context;
44
use tokio::sync::mpsc::unbounded_channel;
55

66
/// Tools for consume iterator which return future.
7-
#[async_trait::async_trait]
87
pub trait FutureConsumer {
98
type Item;
109
/// Use to immediately consume the data produced by the future in the iterator
@@ -13,7 +12,6 @@ pub trait FutureConsumer {
1312
fn fut_consume(self, func: impl FnMut(Self::Item) + Send) -> impl Future<Output = ()>;
1413
}
1514

16-
#[async_trait::async_trait]
1715
impl<I, Fut> FutureConsumer for I
1816
where
1917
I: Iterator<Item = Fut>,
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
use std::future::Future;
2+
13
use rspack_collections::IdentifierSet;
24
use rspack_error::Result;
35

4-
#[async_trait::async_trait]
56
pub trait Backend: std::fmt::Debug + Send + Sync {
6-
async fn current_active_modules(&mut self) -> Result<IdentifierSet>;
7+
fn current_active_modules(&mut self) -> impl Future<Output = Result<IdentifierSet>> + Send + '_;
78
}

0 commit comments

Comments
 (0)