Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(turbopack): Use ResolvedVc for next-api, part 3 #73236

Merged
merged 8 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1149,15 +1149,15 @@ impl AppEndpoint {
)
.await?;
server_assets.insert(server_action_manifest.manifest);
Some(server_action_manifest.loader)
Some(server_action_manifest.loader.to_resolved().await?)
} else {
None
};

let (app_entry_chunks, app_entry_chunks_availability) = &*self
.app_entry_chunks(
client_references,
server_action_manifest_loader,
server_action_manifest_loader.map(|v| *v),
server_path,
process_client_assets,
)
Expand Down
94 changes: 51 additions & 43 deletions crates/next-api/src/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ use crate::{

#[turbo_tasks::value]
pub struct PagesProject {
project: Vc<Project>,
project: ResolvedVc<Project>,
}

#[turbo_tasks::value_impl]
impl PagesProject {
#[turbo_tasks::function]
pub fn new(project: Vc<Project>) -> Vc<Self> {
pub fn new(project: ResolvedVc<Project>) -> Vc<Self> {
PagesProject { project }.cell()
}

Expand Down Expand Up @@ -234,7 +234,7 @@ impl PagesProject {

#[turbo_tasks::function]
fn project(&self) -> Vc<Project> {
self.project
*self.project
}

#[turbo_tasks::function]
Expand Down Expand Up @@ -598,11 +598,11 @@ impl PagesProject {
#[turbo_tasks::value]
struct PageEndpoint {
ty: PageEndpointType,
pages_project: Vc<PagesProject>,
pathname: Vc<RcStr>,
original_name: Vc<RcStr>,
page: Vc<PagesStructureItem>,
pages_structure: Vc<PagesStructure>,
pages_project: ResolvedVc<PagesProject>,
pathname: ResolvedVc<RcStr>,
original_name: ResolvedVc<RcStr>,
page: ResolvedVc<PagesStructureItem>,
pages_structure: ResolvedVc<PagesStructure>,
}

#[derive(
Expand All @@ -629,11 +629,11 @@ impl PageEndpoint {
#[turbo_tasks::function]
fn new(
ty: PageEndpointType,
pages_project: Vc<PagesProject>,
pathname: Vc<RcStr>,
original_name: Vc<RcStr>,
page: Vc<PagesStructureItem>,
pages_structure: Vc<PagesStructure>,
pages_project: ResolvedVc<PagesProject>,
pathname: ResolvedVc<RcStr>,
original_name: ResolvedVc<RcStr>,
page: ResolvedVc<PagesStructureItem>,
pages_structure: ResolvedVc<PagesStructure>,
) -> Vc<Self> {
PageEndpoint {
ty,
Expand All @@ -657,7 +657,7 @@ impl PageEndpoint {
let page_loader = create_page_loader_entry_module(
this.pages_project.client_module_context(),
self.source(),
this.pathname,
*this.pathname,
);
if matches!(
*this.pages_project.project().next_mode().await?,
Expand Down Expand Up @@ -721,7 +721,7 @@ impl PageEndpoint {
let client_relative_path = self.client_relative_path();
let page_loader = PageLoaderAsset::new(
node_root,
this.pathname,
*this.pathname,
client_relative_path,
client_chunks,
);
Expand Down Expand Up @@ -762,13 +762,13 @@ impl PageEndpoint {

let ssr_module = if is_edge {
create_page_ssr_entry_module(
this.pathname,
*this.pathname,
reference_type,
project_root,
Vc::upcast(edge_module_context),
self.source(),
this.original_name,
this.pages_structure,
*this.original_name,
*this.pages_structure,
config.runtime,
this.pages_project.project().next_config(),
)
Expand All @@ -781,13 +781,13 @@ impl PageEndpoint {
ssr_module
} else {
create_page_ssr_entry_module(
this.pathname,
*this.pathname,
reference_type,
project_root,
Vc::upcast(module_context),
self.source(),
this.original_name,
this.pages_structure,
*this.original_name,
*this.pages_structure,
config.runtime,
this.pages_project.project().next_config(),
)
Expand Down Expand Up @@ -836,18 +836,23 @@ impl PageEndpoint {
.context("could not process page loader entry module")?;
evaluatable_assets.push(evaluatable);

let edge_files = edge_chunking_context.evaluated_chunk_group_assets(
ssr_module.ident(),
Vc::cell(evaluatable_assets),
Value::new(AvailabilityInfo::Root),
);
let edge_files = edge_chunking_context
.evaluated_chunk_group_assets(
ssr_module.ident(),
Vc::cell(evaluatable_assets),
Value::new(AvailabilityInfo::Root),
)
.to_resolved()
.await?;

let client_chunking_context =
this.pages_project.project().client_chunking_context();
let dynamic_import_entries = collect_evaluated_chunk_group(
Vc::upcast(client_chunking_context),
dynamic_import_modules,
)
.await?
.to_resolved()
.await?;

Ok(SsrChunk::Edge {
Expand Down Expand Up @@ -882,6 +887,8 @@ impl PageEndpoint {
dynamic_import_modules,
Value::new(AvailabilityInfo::Root),
)
.await?
.to_resolved()
.await?;

let server_asset_trace_file = if this
Expand Down Expand Up @@ -1064,7 +1071,7 @@ impl PageEndpoint {
let pathname = this.pathname.await?;
let original_name = &*this.original_name.await?;

let client_assets = OutputAssets::new(client_assets);
let client_assets = OutputAssets::new(client_assets).to_resolved().await?;

let manifest_path_prefix = get_asset_prefix_from_pathname(&pathname);
let node_root = this.pages_project.project().node_root();
Expand All @@ -1075,7 +1082,7 @@ impl PageEndpoint {
original_name,
&manifest_path_prefix,
&pathname,
client_assets,
*client_assets,
false,
)
.await?;
Expand Down Expand Up @@ -1117,13 +1124,13 @@ impl PageEndpoint {
server_assets.push(pages_manifest);

let loadable_manifest_output =
self.react_loadable_manifest(dynamic_import_entries);
self.react_loadable_manifest(*dynamic_import_entries);
server_assets.extend(loadable_manifest_output.await?.iter().copied());
}

PageEndpointOutput::NodeJs {
entry_chunk: entry,
server_assets: Vc::cell(server_assets),
server_assets: ResolvedVc::cell(server_assets),
client_assets,
}
}
Expand Down Expand Up @@ -1157,7 +1164,7 @@ impl PageEndpoint {
file_paths_from_root
.extend(get_js_paths_from_root(&node_root_value, &files_value).await?);

let all_output_assets = all_assets_from_entries(files).await?;
let all_output_assets = all_assets_from_entries(*files).await?;

wasm_paths_from_root.extend(
get_wasm_paths_from_root(&node_root_value, &all_output_assets).await?,
Expand Down Expand Up @@ -1209,12 +1216,13 @@ impl PageEndpoint {
server_assets.push(ResolvedVc::upcast(middleware_manifest_v2));
}

let loadable_manifest_output = self.react_loadable_manifest(dynamic_import_entries);
let loadable_manifest_output =
self.react_loadable_manifest(*dynamic_import_entries);
server_assets.extend(loadable_manifest_output.await?.iter().copied());

PageEndpointOutput::Edge {
files,
server_assets: Vc::cell(server_assets),
server_assets: ResolvedVc::cell(server_assets),
client_assets,
}
}
Expand Down Expand Up @@ -1359,13 +1367,13 @@ impl Endpoint for PageEndpoint {
enum PageEndpointOutput {
NodeJs {
entry_chunk: ResolvedVc<Box<dyn OutputAsset>>,
server_assets: Vc<OutputAssets>,
client_assets: Vc<OutputAssets>,
server_assets: ResolvedVc<OutputAssets>,
client_assets: ResolvedVc<OutputAssets>,
},
Edge {
files: Vc<OutputAssets>,
server_assets: Vc<OutputAssets>,
client_assets: Vc<OutputAssets>,
files: ResolvedVc<OutputAssets>,
server_assets: ResolvedVc<OutputAssets>,
client_assets: ResolvedVc<OutputAssets>,
},
}

Expand All @@ -1388,15 +1396,15 @@ impl PageEndpointOutput {
pub fn server_assets(&self) -> Vc<OutputAssets> {
match *self {
PageEndpointOutput::NodeJs { server_assets, .. }
| PageEndpointOutput::Edge { server_assets, .. } => server_assets,
| PageEndpointOutput::Edge { server_assets, .. } => *server_assets,
}
}

#[turbo_tasks::function]
pub fn client_assets(&self) -> Vc<OutputAssets> {
match *self {
PageEndpointOutput::NodeJs { client_assets, .. }
| PageEndpointOutput::Edge { client_assets, .. } => client_assets,
| PageEndpointOutput::Edge { client_assets, .. } => *client_assets,
}
}
}
Expand All @@ -1405,11 +1413,11 @@ impl PageEndpointOutput {
pub enum SsrChunk {
NodeJs {
entry: ResolvedVc<Box<dyn OutputAsset>>,
dynamic_import_entries: Vc<DynamicImportedChunks>,
dynamic_import_entries: ResolvedVc<DynamicImportedChunks>,
server_asset_trace_file: ResolvedVc<OptionOutputAsset>,
},
Edge {
files: Vc<OutputAssets>,
dynamic_import_entries: Vc<DynamicImportedChunks>,
files: ResolvedVc<OutputAssets>,
dynamic_import_entries: ResolvedVc<DynamicImportedChunks>,
},
}
16 changes: 10 additions & 6 deletions crates/next-api/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,21 +197,25 @@ pub struct Instrumentation {
pub struct ProjectContainer {
name: RcStr,
options_state: State<Option<ProjectOptions>>,
versioned_content_map: Option<Vc<VersionedContentMap>>,
versioned_content_map: Option<ResolvedVc<VersionedContentMap>>,
}

#[turbo_tasks::value_impl]
impl ProjectContainer {
#[turbo_tasks::function]
pub fn new(name: RcStr, dev: bool) -> Vc<Self> {
ProjectContainer {
pub async fn new(name: RcStr, dev: bool) -> Result<Vc<Self>> {
Ok(ProjectContainer {
name,
// we only need to enable versioning in dev mode, since build
// is assumed to be operating over a static snapshot
versioned_content_map: dev.then(VersionedContentMap::new),
versioned_content_map: if dev {
Some(VersionedContentMap::new().to_resolved().await?)
} else {
None
},
options_state: State::new(None),
}
.cell()
.cell())
}
}

Expand Down Expand Up @@ -384,7 +388,7 @@ impl ProjectContainer {
} else {
NextMode::Build.cell()
},
versioned_content_map: self.versioned_content_map,
versioned_content_map: self.versioned_content_map.map(|v| *v),
build_id,
encryption_key,
preview_props,
Expand Down
Loading