Unverified Commit b6be5323 authored by Donny/강동윤's avatar Donny/강동윤 Committed by GitHub

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

### What?

Use `ResolvedVc<T>` instead of `Vc<T>` for struct fields in `next-api`, but split into multiple PRs.

### Why?

To reduce scope of changes of each PRs so I can debug HMR failures.

### How?
parent 2efe5440
...@@ -1149,7 +1149,7 @@ impl AppEndpoint { ...@@ -1149,7 +1149,7 @@ impl AppEndpoint {
) )
.await?; .await?;
server_assets.insert(server_action_manifest.manifest); server_assets.insert(server_action_manifest.manifest);
Some(server_action_manifest.loader) Some(server_action_manifest.loader.to_resolved().await?)
} else { } else {
None None
}; };
...@@ -1157,7 +1157,7 @@ impl AppEndpoint { ...@@ -1157,7 +1157,7 @@ impl AppEndpoint {
let (app_entry_chunks, app_entry_chunks_availability) = &*self let (app_entry_chunks, app_entry_chunks_availability) = &*self
.app_entry_chunks( .app_entry_chunks(
client_references, client_references,
server_action_manifest_loader, server_action_manifest_loader.map(|v| *v),
server_path, server_path,
process_client_assets, process_client_assets,
) )
......
...@@ -80,13 +80,13 @@ use crate::{ ...@@ -80,13 +80,13 @@ use crate::{
#[turbo_tasks::value] #[turbo_tasks::value]
pub struct PagesProject { pub struct PagesProject {
project: Vc<Project>, project: ResolvedVc<Project>,
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl PagesProject { impl PagesProject {
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn new(project: Vc<Project>) -> Vc<Self> { pub fn new(project: ResolvedVc<Project>) -> Vc<Self> {
PagesProject { project }.cell() PagesProject { project }.cell()
} }
...@@ -234,7 +234,7 @@ impl PagesProject { ...@@ -234,7 +234,7 @@ impl PagesProject {
#[turbo_tasks::function] #[turbo_tasks::function]
fn project(&self) -> Vc<Project> { fn project(&self) -> Vc<Project> {
self.project *self.project
} }
#[turbo_tasks::function] #[turbo_tasks::function]
...@@ -598,11 +598,11 @@ impl PagesProject { ...@@ -598,11 +598,11 @@ impl PagesProject {
#[turbo_tasks::value] #[turbo_tasks::value]
struct PageEndpoint { struct PageEndpoint {
ty: PageEndpointType, ty: PageEndpointType,
pages_project: Vc<PagesProject>, pages_project: ResolvedVc<PagesProject>,
pathname: Vc<RcStr>, pathname: ResolvedVc<RcStr>,
original_name: Vc<RcStr>, original_name: ResolvedVc<RcStr>,
page: Vc<PagesStructureItem>, page: ResolvedVc<PagesStructureItem>,
pages_structure: Vc<PagesStructure>, pages_structure: ResolvedVc<PagesStructure>,
} }
#[derive( #[derive(
...@@ -629,11 +629,11 @@ impl PageEndpoint { ...@@ -629,11 +629,11 @@ impl PageEndpoint {
#[turbo_tasks::function] #[turbo_tasks::function]
fn new( fn new(
ty: PageEndpointType, ty: PageEndpointType,
pages_project: Vc<PagesProject>, pages_project: ResolvedVc<PagesProject>,
pathname: Vc<RcStr>, pathname: ResolvedVc<RcStr>,
original_name: Vc<RcStr>, original_name: ResolvedVc<RcStr>,
page: Vc<PagesStructureItem>, page: ResolvedVc<PagesStructureItem>,
pages_structure: Vc<PagesStructure>, pages_structure: ResolvedVc<PagesStructure>,
) -> Vc<Self> { ) -> Vc<Self> {
PageEndpoint { PageEndpoint {
ty, ty,
...@@ -657,7 +657,7 @@ impl PageEndpoint { ...@@ -657,7 +657,7 @@ impl PageEndpoint {
let page_loader = create_page_loader_entry_module( let page_loader = create_page_loader_entry_module(
this.pages_project.client_module_context(), this.pages_project.client_module_context(),
self.source(), self.source(),
this.pathname, *this.pathname,
); );
if matches!( if matches!(
*this.pages_project.project().next_mode().await?, *this.pages_project.project().next_mode().await?,
...@@ -721,7 +721,7 @@ impl PageEndpoint { ...@@ -721,7 +721,7 @@ impl PageEndpoint {
let client_relative_path = self.client_relative_path(); let client_relative_path = self.client_relative_path();
let page_loader = PageLoaderAsset::new( let page_loader = PageLoaderAsset::new(
node_root, node_root,
this.pathname, *this.pathname,
client_relative_path, client_relative_path,
client_chunks, client_chunks,
); );
...@@ -762,13 +762,13 @@ impl PageEndpoint { ...@@ -762,13 +762,13 @@ impl PageEndpoint {
let ssr_module = if is_edge { let ssr_module = if is_edge {
create_page_ssr_entry_module( create_page_ssr_entry_module(
this.pathname, *this.pathname,
reference_type, reference_type,
project_root, project_root,
Vc::upcast(edge_module_context), Vc::upcast(edge_module_context),
self.source(), self.source(),
this.original_name, *this.original_name,
this.pages_structure, *this.pages_structure,
config.runtime, config.runtime,
this.pages_project.project().next_config(), this.pages_project.project().next_config(),
) )
...@@ -781,13 +781,13 @@ impl PageEndpoint { ...@@ -781,13 +781,13 @@ impl PageEndpoint {
ssr_module ssr_module
} else { } else {
create_page_ssr_entry_module( create_page_ssr_entry_module(
this.pathname, *this.pathname,
reference_type, reference_type,
project_root, project_root,
Vc::upcast(module_context), Vc::upcast(module_context),
self.source(), self.source(),
this.original_name, *this.original_name,
this.pages_structure, *this.pages_structure,
config.runtime, config.runtime,
this.pages_project.project().next_config(), this.pages_project.project().next_config(),
) )
...@@ -836,11 +836,14 @@ impl PageEndpoint { ...@@ -836,11 +836,14 @@ impl PageEndpoint {
.context("could not process page loader entry module")?; .context("could not process page loader entry module")?;
evaluatable_assets.push(evaluatable); evaluatable_assets.push(evaluatable);
let edge_files = edge_chunking_context.evaluated_chunk_group_assets( let edge_files = edge_chunking_context
ssr_module.ident(), .evaluated_chunk_group_assets(
Vc::cell(evaluatable_assets), ssr_module.ident(),
Value::new(AvailabilityInfo::Root), Vc::cell(evaluatable_assets),
); Value::new(AvailabilityInfo::Root),
)
.to_resolved()
.await?;
let client_chunking_context = let client_chunking_context =
this.pages_project.project().client_chunking_context(); this.pages_project.project().client_chunking_context();
...@@ -848,6 +851,8 @@ impl PageEndpoint { ...@@ -848,6 +851,8 @@ impl PageEndpoint {
Vc::upcast(client_chunking_context), Vc::upcast(client_chunking_context),
dynamic_import_modules, dynamic_import_modules,
) )
.await?
.to_resolved()
.await?; .await?;
Ok(SsrChunk::Edge { Ok(SsrChunk::Edge {
...@@ -882,6 +887,8 @@ impl PageEndpoint { ...@@ -882,6 +887,8 @@ impl PageEndpoint {
dynamic_import_modules, dynamic_import_modules,
Value::new(AvailabilityInfo::Root), Value::new(AvailabilityInfo::Root),
) )
.await?
.to_resolved()
.await?; .await?;
let server_asset_trace_file = if this let server_asset_trace_file = if this
...@@ -1064,7 +1071,7 @@ impl PageEndpoint { ...@@ -1064,7 +1071,7 @@ impl PageEndpoint {
let pathname = this.pathname.await?; let pathname = this.pathname.await?;
let original_name = &*this.original_name.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 manifest_path_prefix = get_asset_prefix_from_pathname(&pathname);
let node_root = this.pages_project.project().node_root(); let node_root = this.pages_project.project().node_root();
...@@ -1075,7 +1082,7 @@ impl PageEndpoint { ...@@ -1075,7 +1082,7 @@ impl PageEndpoint {
original_name, original_name,
&manifest_path_prefix, &manifest_path_prefix,
&pathname, &pathname,
client_assets, *client_assets,
false, false,
) )
.await?; .await?;
...@@ -1117,13 +1124,13 @@ impl PageEndpoint { ...@@ -1117,13 +1124,13 @@ impl PageEndpoint {
server_assets.push(pages_manifest); server_assets.push(pages_manifest);
let loadable_manifest_output = 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()); server_assets.extend(loadable_manifest_output.await?.iter().copied());
} }
PageEndpointOutput::NodeJs { PageEndpointOutput::NodeJs {
entry_chunk: entry, entry_chunk: entry,
server_assets: Vc::cell(server_assets), server_assets: ResolvedVc::cell(server_assets),
client_assets, client_assets,
} }
} }
...@@ -1157,7 +1164,7 @@ impl PageEndpoint { ...@@ -1157,7 +1164,7 @@ impl PageEndpoint {
file_paths_from_root file_paths_from_root
.extend(get_js_paths_from_root(&node_root_value, &files_value).await?); .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( wasm_paths_from_root.extend(
get_wasm_paths_from_root(&node_root_value, &all_output_assets).await?, get_wasm_paths_from_root(&node_root_value, &all_output_assets).await?,
...@@ -1209,12 +1216,13 @@ impl PageEndpoint { ...@@ -1209,12 +1216,13 @@ impl PageEndpoint {
server_assets.push(ResolvedVc::upcast(middleware_manifest_v2)); 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()); server_assets.extend(loadable_manifest_output.await?.iter().copied());
PageEndpointOutput::Edge { PageEndpointOutput::Edge {
files, files,
server_assets: Vc::cell(server_assets), server_assets: ResolvedVc::cell(server_assets),
client_assets, client_assets,
} }
} }
...@@ -1359,13 +1367,13 @@ impl Endpoint for PageEndpoint { ...@@ -1359,13 +1367,13 @@ impl Endpoint for PageEndpoint {
enum PageEndpointOutput { enum PageEndpointOutput {
NodeJs { NodeJs {
entry_chunk: ResolvedVc<Box<dyn OutputAsset>>, entry_chunk: ResolvedVc<Box<dyn OutputAsset>>,
server_assets: Vc<OutputAssets>, server_assets: ResolvedVc<OutputAssets>,
client_assets: Vc<OutputAssets>, client_assets: ResolvedVc<OutputAssets>,
}, },
Edge { Edge {
files: Vc<OutputAssets>, files: ResolvedVc<OutputAssets>,
server_assets: Vc<OutputAssets>, server_assets: ResolvedVc<OutputAssets>,
client_assets: Vc<OutputAssets>, client_assets: ResolvedVc<OutputAssets>,
}, },
} }
...@@ -1388,7 +1396,7 @@ impl PageEndpointOutput { ...@@ -1388,7 +1396,7 @@ impl PageEndpointOutput {
pub fn server_assets(&self) -> Vc<OutputAssets> { pub fn server_assets(&self) -> Vc<OutputAssets> {
match *self { match *self {
PageEndpointOutput::NodeJs { server_assets, .. } PageEndpointOutput::NodeJs { server_assets, .. }
| PageEndpointOutput::Edge { server_assets, .. } => server_assets, | PageEndpointOutput::Edge { server_assets, .. } => *server_assets,
} }
} }
...@@ -1396,7 +1404,7 @@ impl PageEndpointOutput { ...@@ -1396,7 +1404,7 @@ impl PageEndpointOutput {
pub fn client_assets(&self) -> Vc<OutputAssets> { pub fn client_assets(&self) -> Vc<OutputAssets> {
match *self { match *self {
PageEndpointOutput::NodeJs { client_assets, .. } PageEndpointOutput::NodeJs { client_assets, .. }
| PageEndpointOutput::Edge { client_assets, .. } => client_assets, | PageEndpointOutput::Edge { client_assets, .. } => *client_assets,
} }
} }
} }
...@@ -1405,11 +1413,11 @@ impl PageEndpointOutput { ...@@ -1405,11 +1413,11 @@ impl PageEndpointOutput {
pub enum SsrChunk { pub enum SsrChunk {
NodeJs { NodeJs {
entry: ResolvedVc<Box<dyn OutputAsset>>, entry: ResolvedVc<Box<dyn OutputAsset>>,
dynamic_import_entries: Vc<DynamicImportedChunks>, dynamic_import_entries: ResolvedVc<DynamicImportedChunks>,
server_asset_trace_file: ResolvedVc<OptionOutputAsset>, server_asset_trace_file: ResolvedVc<OptionOutputAsset>,
}, },
Edge { Edge {
files: Vc<OutputAssets>, files: ResolvedVc<OutputAssets>,
dynamic_import_entries: Vc<DynamicImportedChunks>, dynamic_import_entries: ResolvedVc<DynamicImportedChunks>,
}, },
} }
...@@ -197,21 +197,25 @@ pub struct Instrumentation { ...@@ -197,21 +197,25 @@ pub struct Instrumentation {
pub struct ProjectContainer { pub struct ProjectContainer {
name: RcStr, name: RcStr,
options_state: State<Option<ProjectOptions>>, options_state: State<Option<ProjectOptions>>,
versioned_content_map: Option<Vc<VersionedContentMap>>, versioned_content_map: Option<ResolvedVc<VersionedContentMap>>,
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl ProjectContainer { impl ProjectContainer {
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn new(name: RcStr, dev: bool) -> Vc<Self> { pub async fn new(name: RcStr, dev: bool) -> Result<Vc<Self>> {
ProjectContainer { Ok(ProjectContainer {
name, name,
// we only need to enable versioning in dev mode, since build // we only need to enable versioning in dev mode, since build
// is assumed to be operating over a static snapshot // 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), options_state: State::new(None),
} }
.cell() .cell())
} }
} }
...@@ -384,7 +388,7 @@ impl ProjectContainer { ...@@ -384,7 +388,7 @@ impl ProjectContainer {
} else { } else {
NextMode::Build.cell() NextMode::Build.cell()
}, },
versioned_content_map: self.versioned_content_map, versioned_content_map: self.versioned_content_map.map(|v| *v),
build_id, build_id,
encryption_key, encryption_key,
preview_props, preview_props,
......
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