From c498aa35061d320d78b59e8ae63782b6b2398889 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Fri, 15 Sep 2023 17:56:31 +0200 Subject: [PATCH] reduce number of task in async_module (vercel/turbo#5959) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Description ### Testing Instructions Closes WEB-1580 --- .../src/references/async_module.rs | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/crates/turbopack-ecmascript/src/references/async_module.rs b/crates/turbopack-ecmascript/src/references/async_module.rs index a549caa76fdba..cda5cb48d14ed 100644 --- a/crates/turbopack-ecmascript/src/references/async_module.rs +++ b/crates/turbopack-ecmascript/src/references/async_module.rs @@ -6,7 +6,7 @@ use swc_core::{ ecma::ast::{ArrayLit, ArrayPat, Expr, Ident, Pat, Program}, quote, }; -use turbo_tasks::{primitives::Bools, trace::TraceRawVcs, TryFlatJoinIterExt, Value, Vc}; +use turbo_tasks::{trace::TraceRawVcs, TryFlatJoinIterExt, Value, Vc}; use turbopack_core::chunk::availability_info::AvailabilityInfo; use super::esm::base::ReferencedAsset; @@ -102,17 +102,6 @@ struct AsyncModuleScc { #[turbo_tasks::value(transparent)] struct OptionAsyncModuleScc(Option>); -#[turbo_tasks::function] -async fn is_placeable_self_async( - placeable: Vc>, -) -> Result> { - let Some(async_module) = &*placeable.get_async_module().await? else { - return Ok(Vc::cell(false)); - }; - - Ok(async_module.is_self_async()) -} - #[turbo_tasks::value_impl] impl AsyncModuleScc { #[turbo_tasks::function] @@ -124,19 +113,23 @@ impl AsyncModuleScc { async fn is_async(self: Vc) -> Result> { let this = self.await?; - let mut bools = Vec::new(); - for placeable in &*this.scc.await? { - bools.push(is_placeable_self_async(*placeable)); + if let Some(async_module) = &*placeable.get_async_module().await? { + if *async_module.is_self_async().await? { + return Ok(Vc::cell(true)); + } + } } for scc in &*this.scope.get_scc_children(this.scc).await? { // Because we generated SCCs there can be no loops in the children, so calling // recursively is fine. - bools.push(AsyncModuleScc::new(*scc, this.scope).is_async()); + if *AsyncModuleScc::new(*scc, this.scope).is_async().await? { + return Ok(Vc::cell(true)); + } } - Ok(Vc::::cell(bools).any()) + Ok(Vc::cell(false)) } }