Unverified Commit 7d82b682 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Turbopack: parallelize app structure (#63707)

### What?

Allow to scan app structure in parallel


Closes PACK-2845
parent 93aac0e3
...@@ -9,8 +9,8 @@ use indexmap::{ ...@@ -9,8 +9,8 @@ use indexmap::{
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tracing::Instrument; use tracing::Instrument;
use turbo_tasks::{ use turbo_tasks::{
debug::ValueDebugFormat, trace::TraceRawVcs, Completion, Completions, TaskInput, ValueToString, debug::ValueDebugFormat, trace::TraceRawVcs, Completion, Completions, TaskInput,
Vc, TryJoinIterExt, ValueToString, Vc,
}; };
use turbopack_binding::{ use turbopack_binding::{
turbo::tasks_fs::{DirectoryContent, DirectoryEntry, FileSystemEntryType, FileSystemPath}, turbo::tasks_fs::{DirectoryContent, DirectoryEntry, FileSystemEntryType, FileSystemPath},
...@@ -1076,50 +1076,75 @@ async fn directory_tree_to_entrypoints_internal_untraced( ...@@ -1076,50 +1076,75 @@ async fn directory_tree_to_entrypoints_internal_untraced(
} }
} }
for (subdir_name, &subdirectory) in subdirectories.iter() { let app_page = &app_page;
let mut child_app_page = app_page.clone(); let directory_name = &directory_name;
let mut illegal_path = None; let subdirectories = subdirectories
.iter()
// When constructing the app_page fails (e. g. due to limitations of the order), .map(|(subdir_name, &subdirectory)| async move {
// we only want to emit the error when there are actual pages below that let mut child_app_page = app_page.clone();
// directory. let mut illegal_path = None;
if let Err(e) = child_app_page.push_str(subdir_name) {
illegal_path = Some(e); // When constructing the app_page fails (e. g. due to limitations of the order),
} // we only want to emit the error when there are actual pages below that
// directory.
let map = directory_tree_to_entrypoints_internal( if let Err(e) = child_app_page.push_str(subdir_name) {
app_dir, illegal_path = Some(e);
global_metadata, }
subdir_name.to_string(),
subdirectory,
child_app_page.clone(),
)
.await?;
if let Some(illegal_path) = illegal_path { let map = directory_tree_to_entrypoints_internal(
if !map.is_empty() { app_dir,
return Err(illegal_path); global_metadata,
subdir_name.to_string(),
subdirectory,
child_app_page.clone(),
)
.await?;
if let Some(illegal_path) = illegal_path {
if !map.is_empty() {
return Err(illegal_path);
}
} }
}
for (_, entrypoint) in map.iter() { let mut loader_trees = Vec::new();
match *entrypoint {
Entrypoint::AppPage { for (_, entrypoint) in map.iter() {
if let Entrypoint::AppPage {
ref pages, ref pages,
loader_tree: _, loader_tree: _,
} => { } = *entrypoint
{
for page in pages { for page in pages {
let app_path = AppPath::from(page.clone()); let app_path = AppPath::from(page.clone());
let loader_tree = *directory_tree_to_loader_tree( let loader_tree = directory_tree_to_loader_tree(
app_dir, app_dir,
global_metadata, global_metadata,
directory_name.clone(), directory_name.clone(),
directory_tree_vc, directory_tree_vc,
app_page.clone(), app_page.clone(),
app_path, app_path,
) );
.await?; loader_trees.push(loader_tree);
}
}
}
Ok((map, loader_trees))
})
.try_join()
.await?;
for (map, loader_trees) in subdirectories.iter() {
let mut i = 0;
for (_, entrypoint) in map.iter() {
match *entrypoint {
Entrypoint::AppPage {
ref pages,
loader_tree: _,
} => {
for page in pages {
let loader_tree = *loader_trees[i].await?;
i += 1;
add_app_page( add_app_page(
app_dir, app_dir,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment