Skip to content

Commit

Permalink
reduce number of task in async_module (vercel/turborepo#5959)
Browse files Browse the repository at this point in the history
### Description

<!--
  ✍️ Write a short summary of your work.
  If necessary, include relevant screenshots.
-->

### Testing Instructions

<!--
  Give a quick description of steps to test your changes.
-->


Closes WEB-1580
  • Loading branch information
sokra authored Sep 15, 2023
1 parent 0abbdb6 commit c498aa3
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions crates/turbopack-ecmascript/src/references/async_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -102,17 +102,6 @@ struct AsyncModuleScc {
#[turbo_tasks::value(transparent)]
struct OptionAsyncModuleScc(Option<Vc<AsyncModuleScc>>);

#[turbo_tasks::function]
async fn is_placeable_self_async(
placeable: Vc<Box<dyn EcmascriptChunkPlaceable>>,
) -> Result<Vc<bool>> {
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]
Expand All @@ -124,19 +113,23 @@ impl AsyncModuleScc {
async fn is_async(self: Vc<Self>) -> Result<Vc<bool>> {
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::<Bools>::cell(bools).any())
Ok(Vc::cell(false))
}
}

Expand Down

0 comments on commit c498aa3

Please sign in to comment.