Unverified Commit 3e8fe3c7 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

add user-level tracing (#59284)

### What?

add a few user-focused info-level spans to allow high-level tracing on a
normal build.

`NEXT_TURBOPACK_TRACING=1` can be used to generate a `.next/trace.log`
file

### Why?

Gain insight into build performance and module cost 



Closes PACK-2083
parent faa44210
...@@ -81,6 +81,7 @@ fn test(input: &Path, minify: bool) { ...@@ -81,6 +81,7 @@ fn test(input: &Path, minify: bool) {
auto_modularize_imports: None, auto_modularize_imports: None,
optimize_barrel_exports: None, optimize_barrel_exports: None,
optimize_server_react: None, optimize_server_react: None,
prefer_esm: false,
}; };
let unresolved_mark = Mark::new(); let unresolved_mark = Mark::new();
......
...@@ -5,6 +5,7 @@ use next_api::{ ...@@ -5,6 +5,7 @@ use next_api::{
route::{Endpoint, WrittenEndpoint}, route::{Endpoint, WrittenEndpoint},
server_paths::ServerPath, server_paths::ServerPath,
}; };
use tracing::Instrument;
use turbo_tasks::Vc; use turbo_tasks::Vc;
use turbopack_binding::turbopack::core::error::PrettyPrintError; use turbopack_binding::turbopack::core::error::PrettyPrintError;
...@@ -114,16 +115,19 @@ pub fn endpoint_server_changed_subscribe( ...@@ -114,16 +115,19 @@ pub fn endpoint_server_changed_subscribe(
subscribe( subscribe(
turbo_tasks, turbo_tasks,
func, func,
move || async move { move || {
let changed = endpoint.server_changed(); async move {
changed.strongly_consistent().await?; let changed = endpoint.server_changed();
if issues { changed.strongly_consistent().await?;
let issues = get_issues(changed).await?; if issues {
let diags = get_diagnostics(changed).await?; let issues = get_issues(changed).await?;
Ok((issues, diags)) let diags = get_diagnostics(changed).await?;
} else { Ok((issues, diags))
Ok((vec![], vec![])) } else {
Ok((vec![], vec![]))
}
} }
.instrument(tracing::info_span!("server changes subscription"))
}, },
|ctx| { |ctx| {
let (issues, diags) = ctx.value; let (issues, diags) = ctx.value;
...@@ -146,12 +150,15 @@ pub fn endpoint_client_changed_subscribe( ...@@ -146,12 +150,15 @@ pub fn endpoint_client_changed_subscribe(
subscribe( subscribe(
turbo_tasks, turbo_tasks,
func, func,
move || async move { move || {
let changed = endpoint.client_changed(); async move {
// We don't capture issues and diagonistics here since we don't want to be let changed = endpoint.client_changed();
// notified when they change // We don't capture issues and diagonistics here since we don't want to be
changed.strongly_consistent().await?; // notified when they change
Ok(()) changed.strongly_consistent().await?;
Ok(())
}
.instrument(tracing::info_span!("client changes subscription"))
}, },
|_| { |_| {
Ok(vec![TurbopackResult { Ok(vec![TurbopackResult {
......
...@@ -14,8 +14,10 @@ use next_api::{ ...@@ -14,8 +14,10 @@ use next_api::{
route::{Endpoint, Route}, route::{Endpoint, Route},
}; };
use next_core::tracing_presets::{ use next_core::tracing_presets::{
TRACING_NEXT_TARGETS, TRACING_NEXT_TURBOPACK_TARGETS, TRACING_NEXT_TURBO_TASKS_TARGETS, TRACING_NEXT_OVERVIEW_TARGETS, TRACING_NEXT_TARGETS, TRACING_NEXT_TURBOPACK_TARGETS,
TRACING_NEXT_TURBO_TASKS_TARGETS,
}; };
use tracing::Instrument;
use tracing_subscriber::{ use tracing_subscriber::{
prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, EnvFilter, Registry, prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, EnvFilter, Registry,
}; };
...@@ -36,7 +38,6 @@ use turbopack_binding::{ ...@@ -36,7 +38,6 @@ use turbopack_binding::{
exit::ExitGuard, exit::ExitGuard,
raw_trace::RawTraceLayer, raw_trace::RawTraceLayer,
trace_writer::{TraceWriter, TraceWriterGuard}, trace_writer::{TraceWriter, TraceWriterGuard},
tracing_presets::TRACING_OVERVIEW_TARGETS,
}, },
}, },
}; };
...@@ -216,8 +217,8 @@ pub async fn project_new( ...@@ -216,8 +217,8 @@ pub async fn project_new(
let guard = if let Some(mut trace) = trace { let guard = if let Some(mut trace) = trace {
// Trace presets // Trace presets
match trace.as_str() { match trace.as_str() {
"overview" => { "overview" | "1" => {
trace = TRACING_OVERVIEW_TARGETS.join(","); trace = TRACING_NEXT_OVERVIEW_TARGETS.join(",");
} }
"next" => { "next" => {
trace = TRACING_NEXT_TARGETS.join(","); trace = TRACING_NEXT_TARGETS.join(",");
...@@ -433,14 +434,17 @@ pub fn project_entrypoints_subscribe( ...@@ -433,14 +434,17 @@ pub fn project_entrypoints_subscribe(
subscribe( subscribe(
turbo_tasks.clone(), turbo_tasks.clone(),
func, func,
move || async move { move || {
let entrypoints_operation = container.entrypoints(); async move {
let entrypoints = entrypoints_operation.strongly_consistent().await?; let entrypoints_operation = container.entrypoints();
let entrypoints = entrypoints_operation.strongly_consistent().await?;
let issues = get_issues(entrypoints_operation).await?; let issues = get_issues(entrypoints_operation).await?;
let diags = get_diagnostics(entrypoints_operation).await?; let diags = get_diagnostics(entrypoints_operation).await?;
Ok((entrypoints, issues, diags)) Ok((entrypoints, issues, diags))
}
.instrument(tracing::info_span!("entrypoints subscription"))
}, },
move |ctx| { move |ctx| {
let (entrypoints, issues, diags) = ctx.value; let (entrypoints, issues, diags) = ctx.value;
...@@ -500,10 +504,10 @@ pub fn project_hmr_events( ...@@ -500,10 +504,10 @@ pub fn project_hmr_events(
turbo_tasks.clone(), turbo_tasks.clone(),
func, func,
{ {
let identifier = identifier.clone(); let outer_identifier = identifier.clone();
let session = session.clone(); let session = session.clone();
move || { move || {
let identifier = identifier.clone(); let identifier = outer_identifier.clone();
let session = session.clone(); let session = session.clone();
async move { async move {
let state = project let state = project
...@@ -524,6 +528,10 @@ pub fn project_hmr_events( ...@@ -524,6 +528,10 @@ pub fn project_hmr_events(
} }
Ok((update, issues, diags)) Ok((update, issues, diags))
} }
.instrument(tracing::info_span!(
"HMR subscription",
identifier = outer_identifier
))
} }
}, },
move |ctx| { move |ctx| {
......
...@@ -35,6 +35,7 @@ use next_core::{ ...@@ -35,6 +35,7 @@ use next_core::{
util::{get_asset_prefix_from_pathname, NextRuntime}, util::{get_asset_prefix_from_pathname, NextRuntime},
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tracing::Instrument;
use turbo_tasks::{trace::TraceRawVcs, Completion, TryFlatJoinIterExt, TryJoinIterExt, Value, Vc}; use turbo_tasks::{trace::TraceRawVcs, Completion, TryFlatJoinIterExt, TryJoinIterExt, Value, Vc};
use turbopack_binding::{ use turbopack_binding::{
turbo::{ turbo::{
...@@ -1084,37 +1085,61 @@ async fn concatenate_output_assets( ...@@ -1084,37 +1085,61 @@ async fn concatenate_output_assets(
impl Endpoint for AppEndpoint { impl Endpoint for AppEndpoint {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn write_to_disk(self: Vc<Self>) -> Result<Vc<WrittenEndpoint>> { async fn write_to_disk(self: Vc<Self>) -> Result<Vc<WrittenEndpoint>> {
let output = self.output();
// Must use self.output_assets() instead of output.output_assets() to make it a
// single operation
let output_assets = self.output_assets();
let this = self.await?; let this = self.await?;
let node_root = this.app_project.project().node_root(); let span = match this.ty {
AppEndpointType::Page {
ty: AppPageEndpointType::Html,
..
} => {
tracing::info_span!("app endpoint HTML", name = display(&this.page))
}
AppEndpointType::Page {
ty: AppPageEndpointType::Rsc,
..
} => {
tracing::info_span!("app endpoint RSC", name = display(&this.page))
}
AppEndpointType::Route { .. } => {
tracing::info_span!("app endpoint route", name = display(&this.page))
}
AppEndpointType::Metadata { .. } => {
tracing::info_span!("app endpoint metadata", name = display(&this.page))
}
};
async move {
let output = self.output();
// Must use self.output_assets() instead of output.output_assets() to make it a
// single operation
let output_assets = self.output_assets();
let node_root_ref = &node_root.await?; let node_root = this.app_project.project().node_root();
let node_root = this.app_project.project().node_root(); let node_root_ref = &node_root.await?;
this.app_project
.project()
.emit_all_output_assets(Vc::cell(output_assets))
.await?;
let server_paths = all_server_paths(output_assets, node_root) let node_root = this.app_project.project().node_root();
.await? this.app_project
.clone_value(); .project()
.emit_all_output_assets(Vc::cell(output_assets))
let written_endpoint = match *output.await? { .await?;
AppEndpointOutput::NodeJs { rsc_chunk, .. } => WrittenEndpoint::NodeJs {
server_entry_path: node_root_ref let server_paths = all_server_paths(output_assets, node_root)
.get_path_to(&*rsc_chunk.ident().path().await?) .await?
.context("Node.js chunk entry path must be inside the node root")? .clone_value();
.to_string(),
server_paths, let written_endpoint = match *output.await? {
}, AppEndpointOutput::NodeJs { rsc_chunk, .. } => WrittenEndpoint::NodeJs {
AppEndpointOutput::Edge { .. } => WrittenEndpoint::Edge { server_paths }, server_entry_path: node_root_ref
}; .get_path_to(&*rsc_chunk.ident().path().await?)
Ok(written_endpoint.cell()) .context("Node.js chunk entry path must be inside the node root")?
.to_string(),
server_paths,
},
AppEndpointOutput::Edge { .. } => WrittenEndpoint::Edge { server_paths },
};
Ok(written_endpoint.cell())
}
.instrument(span)
.await
} }
#[turbo_tasks::function] #[turbo_tasks::function]
......
...@@ -5,6 +5,7 @@ use next_core::{ ...@@ -5,6 +5,7 @@ use next_core::{
next_manifests::{InstrumentationDefinition, MiddlewaresManifestV2}, next_manifests::{InstrumentationDefinition, MiddlewaresManifestV2},
next_server::{get_server_chunking_context, get_server_runtime_entries, ServerContextType}, next_server::{get_server_chunking_context, get_server_runtime_entries, ServerContextType},
}; };
use tracing::Instrument;
use turbo_tasks::{Completion, TryJoinIterExt, Value, Vc}; use turbo_tasks::{Completion, TryJoinIterExt, Value, Vc};
use turbopack_binding::{ use turbopack_binding::{
turbo::tasks_fs::{File, FileContent}, turbo::tasks_fs::{File, FileContent},
...@@ -171,18 +172,23 @@ impl InstrumentationEndpoint { ...@@ -171,18 +172,23 @@ impl InstrumentationEndpoint {
impl Endpoint for InstrumentationEndpoint { impl Endpoint for InstrumentationEndpoint {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn write_to_disk(self: Vc<Self>) -> Result<Vc<WrittenEndpoint>> { async fn write_to_disk(self: Vc<Self>) -> Result<Vc<WrittenEndpoint>> {
let this = self.await?; let span = tracing::info_span!("instrumentation endpoint");
let output_assets = self.output_assets(); async move {
this.project let this = self.await?;
.emit_all_output_assets(Vc::cell(output_assets)) let output_assets = self.output_assets();
.await?; this.project
.emit_all_output_assets(Vc::cell(output_assets))
.await?;
let node_root = this.project.node_root(); let node_root = this.project.node_root();
let server_paths = all_server_paths(output_assets, node_root) let server_paths = all_server_paths(output_assets, node_root)
.await? .await?
.clone_value(); .clone_value();
Ok(WrittenEndpoint::Edge { server_paths }.cell()) Ok(WrittenEndpoint::Edge { server_paths }.cell())
}
.instrument(span)
.await
} }
#[turbo_tasks::function] #[turbo_tasks::function]
......
...@@ -7,6 +7,7 @@ use next_core::{ ...@@ -7,6 +7,7 @@ use next_core::{
next_server::{get_server_runtime_entries, ServerContextType}, next_server::{get_server_runtime_entries, ServerContextType},
util::parse_config_from_source, util::parse_config_from_source,
}; };
use tracing::Instrument;
use turbo_tasks::{Completion, TryJoinIterExt, Value, Vc}; use turbo_tasks::{Completion, TryJoinIterExt, Value, Vc};
use turbopack_binding::{ use turbopack_binding::{
turbo::tasks_fs::{File, FileContent}, turbo::tasks_fs::{File, FileContent},
...@@ -167,18 +168,23 @@ impl MiddlewareEndpoint { ...@@ -167,18 +168,23 @@ impl MiddlewareEndpoint {
impl Endpoint for MiddlewareEndpoint { impl Endpoint for MiddlewareEndpoint {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn write_to_disk(self: Vc<Self>) -> Result<Vc<WrittenEndpoint>> { async fn write_to_disk(self: Vc<Self>) -> Result<Vc<WrittenEndpoint>> {
let this = self.await?; let span = tracing::info_span!("middleware endpoint");
let output_assets = self.output_assets(); async move {
this.project let this = self.await?;
.emit_all_output_assets(Vc::cell(output_assets)) let output_assets = self.output_assets();
.await?; this.project
.emit_all_output_assets(Vc::cell(output_assets))
let node_root = this.project.node_root(); .await?;
let server_paths = all_server_paths(output_assets, node_root)
.await? let node_root = this.project.node_root();
.clone_value(); let server_paths = all_server_paths(output_assets, node_root)
.await?
.clone_value();
Ok(WrittenEndpoint::Edge { server_paths }.cell()) Ok(WrittenEndpoint::Edge { server_paths }.cell())
}
.instrument(span)
.await
} }
#[turbo_tasks::function] #[turbo_tasks::function]
......
...@@ -19,6 +19,7 @@ use next_core::{ ...@@ -19,6 +19,7 @@ use next_core::{
next_telemetry::NextFeatureTelemetry, next_telemetry::NextFeatureTelemetry,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tracing::Instrument;
use turbo_tasks::{ use turbo_tasks::{
debug::ValueDebugFormat, debug::ValueDebugFormat,
graph::{AdjacencyMap, GraphTraversal}, graph::{AdjacencyMap, GraphTraversal},
...@@ -787,19 +788,24 @@ impl Project { ...@@ -787,19 +788,24 @@ impl Project {
self: Vc<Self>, self: Vc<Self>,
output_assets: Vc<OutputAssetsOperation>, output_assets: Vc<OutputAssetsOperation>,
) -> Result<Vc<Completion>> { ) -> Result<Vc<Completion>> {
let all_output_assets = all_assets_from_entries_operation(output_assets); let span = tracing::info_span!("emitting");
async move {
self.await? let all_output_assets = all_assets_from_entries_operation(output_assets);
.versioned_content_map
.insert_output_assets(all_output_assets) self.await?
.await?; .versioned_content_map
.insert_output_assets(all_output_assets)
Ok(emit_assets( .await?;
*all_output_assets.await?,
self.node_root(), Ok(emit_assets(
self.client_relative_path(), *all_output_assets.await?,
self.node_root(), self.node_root(),
)) self.client_relative_path(),
self.node_root(),
))
}
.instrument(span)
.await
} }
#[turbo_tasks::function] #[turbo_tasks::function]
......
...@@ -7,6 +7,7 @@ use next_core::{ ...@@ -7,6 +7,7 @@ use next_core::{
util::{get_asset_prefix_from_pathname, NextRuntime}, util::{get_asset_prefix_from_pathname, NextRuntime},
}; };
use next_swc::server_actions::parse_server_actions; use next_swc::server_actions::parse_server_actions;
use tracing::Instrument;
use turbo_tasks::{ use turbo_tasks::{
graph::{GraphTraversal, NonDeterministic}, graph::{GraphTraversal, NonDeterministic},
TryFlatJoinIterExt, Value, ValueToString, Vc, TryFlatJoinIterExt, Value, ValueToString, Vc,
...@@ -174,52 +175,56 @@ async fn get_actions( ...@@ -174,52 +175,56 @@ async fn get_actions(
server_reference_modules: Vc<Vec<Vc<Box<dyn Module>>>>, server_reference_modules: Vc<Vec<Vc<Box<dyn Module>>>>,
asset_context: Vc<Box<dyn AssetContext>>, asset_context: Vc<Box<dyn AssetContext>>,
) -> Result<Vc<AllActions>> { ) -> Result<Vc<AllActions>> {
let actions = NonDeterministic::new() async move {
.skip_duplicates() let actions = NonDeterministic::new()
.visit( .skip_duplicates()
once((ActionLayer::Rsc, rsc_entry)).chain( .visit(
server_reference_modules once((ActionLayer::Rsc, rsc_entry)).chain(
.await? server_reference_modules
.iter() .await?
.map(|m| (ActionLayer::ActionBrowser, *m)), .iter()
), .map(|m| (ActionLayer::ActionBrowser, *m)),
get_referenced_modules, ),
) get_referenced_modules,
.await )
.completed()? .await
.into_inner() .completed()?
.into_iter() .into_inner()
.map(parse_actions_filter_map) .into_iter()
.try_flat_join() .map(parse_actions_filter_map)
.await?; .try_flat_join()
.await?;
// Actions can be imported by both Client and RSC layers, in which case we need // Actions can be imported by both Client and RSC layers, in which case we need
// to use the RSC layer's module. We do that by merging the hashes (which match // to use the RSC layer's module. We do that by merging the hashes (which match
// in both layers) and preferring the RSC layer's action. // in both layers) and preferring the RSC layer's action.
let mut all_actions: HashToLayerNameModule = IndexMap::new(); let mut all_actions: HashToLayerNameModule = IndexMap::new();
for ((layer, module), actions_map) in actions.iter() { for ((layer, module), actions_map) in actions.iter() {
let module = if *layer == ActionLayer::Rsc { let module = if *layer == ActionLayer::Rsc {
*module *module
} else { } else {
to_rsc_context(*module, asset_context).await? to_rsc_context(*module, asset_context).await?
}; };
for (hash_id, name) in &*actions_map.await? { for (hash_id, name) in &*actions_map.await? {
match all_actions.entry(hash_id.to_owned()) { match all_actions.entry(hash_id.to_owned()) {
Entry::Occupied(e) => { Entry::Occupied(e) => {
if e.get().0 == ActionLayer::ActionBrowser { if e.get().0 == ActionLayer::ActionBrowser {
*e.into_mut() = (*layer, name.to_string(), module); *e.into_mut() = (*layer, name.to_string(), module);
}
}
Entry::Vacant(e) => {
e.insert((*layer, name.to_string(), module));
} }
}
Entry::Vacant(e) => {
e.insert((*layer, name.to_string(), module));
} }
} }
} }
}
all_actions.sort_keys(); all_actions.sort_keys();
Ok(Vc::cell(all_actions)) Ok(Vc::cell(all_actions))
}
.instrument(tracing::info_span!("find server actions"))
.await
} }
/// The ActionBrowser layer's module is in the Client context, and we need to /// The ActionBrowser layer's module is in the Client context, and we need to
......
...@@ -7,6 +7,7 @@ use indexmap::{ ...@@ -7,6 +7,7 @@ use indexmap::{
IndexMap, IndexMap,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tracing::Instrument;
use turbo_tasks::{ use turbo_tasks::{
debug::ValueDebugFormat, trace::TraceRawVcs, Completion, Completions, TaskInput, ValueToString, debug::ValueDebugFormat, trace::TraceRawVcs, Completion, Completions, TaskInput, ValueToString,
Vc, Vc,
...@@ -280,6 +281,19 @@ pub async fn find_app_dir_if_enabled(project_path: Vc<FileSystemPath>) -> Result ...@@ -280,6 +281,19 @@ pub async fn find_app_dir_if_enabled(project_path: Vc<FileSystemPath>) -> Result
async fn get_directory_tree( async fn get_directory_tree(
dir: Vc<FileSystemPath>, dir: Vc<FileSystemPath>,
page_extensions: Vc<Vec<String>>, page_extensions: Vc<Vec<String>>,
) -> Result<Vc<DirectoryTree>> {
let span = {
let dir = dir.to_string().await?;
tracing::info_span!("read app directory tree", name = *dir)
};
get_directory_tree_internal(dir, page_extensions)
.instrument(span)
.await
}
async fn get_directory_tree_internal(
dir: Vc<FileSystemPath>,
page_extensions: Vc<Vec<String>>,
) -> Result<Vc<DirectoryTree>> { ) -> Result<Vc<DirectoryTree>> {
let DirectoryContent::Entries(entries) = &*dir.read_dir().await? else { let DirectoryContent::Entries(entries) = &*dir.read_dir().await? else {
bail!("{} must be a directory", dir.to_string().await?); bail!("{} must be a directory", dir.to_string().await?);
...@@ -297,6 +311,7 @@ async fn get_directory_tree( ...@@ -297,6 +311,7 @@ async fn get_directory_tree(
for (basename, entry) in entries { for (basename, entry) in entries {
match *entry { match *entry {
DirectoryEntry::File(file) => { DirectoryEntry::File(file) => {
let file = file.resolve().await?;
if let Some((stem, ext)) = basename.split_once('.') { if let Some((stem, ext)) = basename.split_once('.') {
if page_extensions_value.iter().any(|e| e == ext) { if page_extensions_value.iter().any(|e| e == ext) {
match stem { match stem {
...@@ -362,6 +377,7 @@ async fn get_directory_tree( ...@@ -362,6 +377,7 @@ async fn get_directory_tree(
)); ));
} }
DirectoryEntry::Directory(dir) => { DirectoryEntry::Directory(dir) => {
let dir = dir.resolve().await?;
// appDir ignores paths starting with an underscore // appDir ignores paths starting with an underscore
if !basename.starts_with('_') { if !basename.starts_with('_') {
let result = get_directory_tree(dir, page_extensions); let result = get_directory_tree(dir, page_extensions);
...@@ -864,6 +880,25 @@ async fn directory_tree_to_entrypoints_internal( ...@@ -864,6 +880,25 @@ async fn directory_tree_to_entrypoints_internal(
directory_name: String, directory_name: String,
directory_tree: Vc<DirectoryTree>, directory_tree: Vc<DirectoryTree>,
app_page: AppPage, app_page: AppPage,
) -> Result<Vc<Entrypoints>> {
let span = tracing::info_span!("build layout trees", name = display(&app_page));
directory_tree_to_entrypoints_internal_untraced(
app_dir,
global_metadata,
directory_name,
directory_tree,
app_page,
)
.instrument(span)
.await
}
async fn directory_tree_to_entrypoints_internal_untraced(
app_dir: Vc<FileSystemPath>,
global_metadata: Vc<GlobalMetadata>,
directory_name: String,
directory_tree: Vc<DirectoryTree>,
app_page: AppPage,
) -> Result<Vc<Entrypoints>> { ) -> Result<Vc<Entrypoints>> {
let mut result = IndexMap::new(); let mut result = IndexMap::new();
...@@ -954,26 +989,26 @@ async fn directory_tree_to_entrypoints_internal( ...@@ -954,26 +989,26 @@ async fn directory_tree_to_entrypoints_internal(
// is considered as its own entry point. // is considered as its own entry point.
if let Some(_not_found) = components.not_found { if let Some(_not_found) = components.not_found {
let dev_not_found_tree = LoaderTree { let dev_not_found_tree = LoaderTree {
page: app_page.clone(), page: app_page.clone(),
segment: directory_name.clone(), segment: directory_name.clone(),
parallel_routes: indexmap! { parallel_routes: indexmap! {
"children".to_string() => LoaderTree { "children".to_string() => LoaderTree {
page: app_page.clone(), page: app_page.clone(),
segment: "__DEFAULT__".to_string(), segment: "__DEFAULT__".to_string(),
parallel_routes: IndexMap::new(), parallel_routes: IndexMap::new(),
components: Components { components: Components {
default: Some(get_next_package(app_dir).join("dist/client/components/parallel-route-default.js".to_string())), default: Some(get_next_package(app_dir).join("dist/client/components/parallel-route-default.js".to_string())),
..Default::default() ..Default::default()
}
.cell(),
global_metadata,
} }
.cell(), .cell(),
global_metadata, },
} components: components.without_leafs().cell(),
.cell(), global_metadata,
}, }
components: components.without_leafs().cell(), .cell();
global_metadata,
}
.cell();
{ {
let app_page = app_page.clone_push_str("not-found")?; let app_page = app_page.clone_push_str("not-found")?;
...@@ -987,26 +1022,26 @@ async fn directory_tree_to_entrypoints_internal( ...@@ -987,26 +1022,26 @@ async fn directory_tree_to_entrypoints_internal(
// Create default not-found page for production if there's no customized // Create default not-found page for production if there's no customized
// not-found // not-found
let prod_not_found_tree = LoaderTree { let prod_not_found_tree = LoaderTree {
page: app_page.clone(), page: app_page.clone(),
segment: directory_name.to_string(), segment: directory_name.to_string(),
parallel_routes: indexmap! { parallel_routes: indexmap! {
"children".to_string() => LoaderTree { "children".to_string() => LoaderTree {
page: app_page.clone(), page: app_page.clone(),
segment: "__PAGE__".to_string(), segment: "__PAGE__".to_string(),
parallel_routes: IndexMap::new(), parallel_routes: IndexMap::new(),
components: Components { components: Components {
page: Some(get_next_package(app_dir).join("dist/client/components/not-found-error.js".to_string())), page: Some(get_next_package(app_dir).join("dist/client/components/not-found-error.js".to_string())),
..Default::default() ..Default::default()
}
.cell(),
global_metadata,
} }
.cell(), .cell(),
global_metadata, },
} components: components.without_leafs().cell(),
.cell(), global_metadata,
}, }
components: components.without_leafs().cell(), .cell();
global_metadata,
}
.cell();
let app_page = app_page.clone_push_str("_not-found")?; let app_page = app_page.clone_push_str("_not-found")?;
add_app_page(app_dir, &mut result, app_page, prod_not_found_tree).await?; add_app_page(app_dir, &mut result, app_page, prod_not_found_tree).await?;
......
use anyhow::Result; use anyhow::Result;
use indexmap::IndexMap; use indexmap::IndexMap;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tracing::Instrument;
use turbo_tasks::{ use turbo_tasks::{
debug::ValueDebugFormat, trace::TraceRawVcs, TryFlatJoinIterExt, TryJoinIterExt, Vc, debug::ValueDebugFormat, trace::TraceRawVcs, TryFlatJoinIterExt, TryJoinIterExt, Vc,
}; };
...@@ -35,42 +36,49 @@ pub async fn get_app_client_references_chunks( ...@@ -35,42 +36,49 @@ pub async fn get_app_client_references_chunks(
client_chunking_context: Vc<Box<dyn EcmascriptChunkingContext>>, client_chunking_context: Vc<Box<dyn EcmascriptChunkingContext>>,
ssr_chunking_context: Vc<Box<dyn EcmascriptChunkingContext>>, ssr_chunking_context: Vc<Box<dyn EcmascriptChunkingContext>>,
) -> Result<Vc<ClientReferencesChunks>> { ) -> Result<Vc<ClientReferencesChunks>> {
let app_client_references_chunks: IndexMap<_, _> = app_client_reference_types async move {
.await? let app_client_references_chunks: IndexMap<_, _> = app_client_reference_types
.iter() .await?
.map(|client_reference_ty| async move { .iter()
Ok(( .map(|client_reference_ty| async move {
*client_reference_ty, Ok((
match client_reference_ty { *client_reference_ty,
ClientReferenceType::EcmascriptClientReference(ecmascript_client_reference) => { match client_reference_ty {
let ecmascript_client_reference_ref = ecmascript_client_reference.await?; ClientReferenceType::EcmascriptClientReference(
ClientReferenceChunks { ecmascript_client_reference,
client_chunks: client_chunking_context.root_chunk_group(Vc::upcast( ) => {
ecmascript_client_reference_ref.client_module, let ecmascript_client_reference_ref =
)), ecmascript_client_reference.await?;
ssr_chunks: ssr_chunking_context.root_chunk_group(Vc::upcast( ClientReferenceChunks {
ecmascript_client_reference_ref.ssr_module, client_chunks: client_chunking_context.root_chunk_group(
)), Vc::upcast(ecmascript_client_reference_ref.client_module),
),
ssr_chunks: ssr_chunking_context.root_chunk_group(Vc::upcast(
ecmascript_client_reference_ref.ssr_module,
)),
}
} }
} ClientReferenceType::CssClientReference(css_client_reference) => {
ClientReferenceType::CssClientReference(css_client_reference) => { let css_client_reference_ref = css_client_reference.await?;
let css_client_reference_ref = css_client_reference.await?; ClientReferenceChunks {
ClientReferenceChunks { client_chunks: client_chunking_context.root_chunk_group(
client_chunks: client_chunking_context.root_chunk_group(Vc::upcast( Vc::upcast(css_client_reference_ref.client_module),
css_client_reference_ref.client_module, ),
)), ssr_chunks: OutputAssets::empty(),
ssr_chunks: OutputAssets::empty(), }
} }
} },
}, ))
)) })
}) .try_join()
.try_join() .await?
.await? .into_iter()
.into_iter() .collect();
.collect();
Ok(Vc::cell(app_client_references_chunks)) Ok(Vc::cell(app_client_references_chunks))
}
.instrument(tracing::info_span!("process client references"))
.await
} }
/// Crawls all modules emitted in the client transition, returning a list of all /// Crawls all modules emitted in the client transition, returning a list of all
......
...@@ -3,6 +3,7 @@ use std::future::Future; ...@@ -3,6 +3,7 @@ use std::future::Future;
use anyhow::Result; use anyhow::Result;
use indexmap::IndexSet; use indexmap::IndexSet;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tracing::Instrument;
use turbo_tasks::{ use turbo_tasks::{
debug::ValueDebugFormat, debug::ValueDebugFormat,
graph::{AdjacencyMap, GraphTraversal, Visit, VisitControlFlow}, graph::{AdjacencyMap, GraphTraversal, Visit, VisitControlFlow},
...@@ -61,26 +62,30 @@ pub struct ClientReferenceGraph { ...@@ -61,26 +62,30 @@ pub struct ClientReferenceGraph {
impl ClientReferenceGraph { impl ClientReferenceGraph {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn new(entries: Vc<Modules>) -> Result<Vc<Self>> { pub async fn new(entries: Vc<Modules>) -> Result<Vc<Self>> {
let entries = entries.await?; async move {
let entries = entries.await?;
let graph = AdjacencyMap::new()
.skip_duplicates() let graph = AdjacencyMap::new()
.visit( .skip_duplicates()
entries .visit(
.iter() entries
.copied() .iter()
.map(|module| VisitClientReferenceNode { .copied()
server_component: None, .map(|module| VisitClientReferenceNode {
ty: VisitClientReferenceNodeType::Internal(module), server_component: None,
}) ty: VisitClientReferenceNodeType::Internal(module),
.collect::<Vec<_>>(), })
VisitClientReference, .collect::<Vec<_>>(),
) VisitClientReference,
.await )
.completed()? .await
.into_inner(); .completed()?
.into_inner();
Ok(ClientReferenceGraph { graph }.cell())
Ok(ClientReferenceGraph { graph }.cell())
}
.instrument(tracing::info_span!("find client references"))
.await
} }
#[turbo_tasks::function] #[turbo_tasks::function]
......
use std::future::Future; use std::future::Future;
use anyhow::Result; use anyhow::Result;
use tracing::Instrument;
use turbo_tasks::{ use turbo_tasks::{
graph::{AdjacencyMap, GraphTraversal, Visit, VisitControlFlow}, graph::{AdjacencyMap, GraphTraversal, Visit, VisitControlFlow},
TryJoinIterExt, Vc, TryJoinIterExt, Vc,
...@@ -19,38 +20,42 @@ pub struct NextDynamicEntries(Vec<Vc<NextDynamicEntryModule>>); ...@@ -19,38 +20,42 @@ pub struct NextDynamicEntries(Vec<Vc<NextDynamicEntryModule>>);
impl NextDynamicEntries { impl NextDynamicEntries {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn from_entries(entries: Vc<Modules>) -> Result<Vc<NextDynamicEntries>> { pub async fn from_entries(entries: Vc<Modules>) -> Result<Vc<NextDynamicEntries>> {
let nodes: Vec<_> = AdjacencyMap::new() async move {
.skip_duplicates() let nodes: Vec<_> = AdjacencyMap::new()
.visit( .skip_duplicates()
entries .visit(
.await? entries
.iter() .await?
.copied() .iter()
.map(VisitDynamicNode::Internal) .copied()
.collect::<Vec<_>>(), .map(VisitDynamicNode::Internal)
VisitDynamic, .collect::<Vec<_>>(),
) VisitDynamic,
.await )
.completed()? .await
.into_inner() .completed()?
.into_reverse_topological() .into_inner()
.collect(); .into_reverse_topological()
.collect();
let mut next_dynamics = vec![];
let mut next_dynamics = vec![];
for node in nodes {
match node { for node in nodes {
VisitDynamicNode::Internal(_asset) => { match node {
// No-op. These nodes are only useful during graph VisitDynamicNode::Internal(_asset) => {
// traversal. // No-op. These nodes are only useful during graph
} // traversal.
VisitDynamicNode::Dynamic(dynamic_asset) => { }
next_dynamics.push(dynamic_asset); VisitDynamicNode::Dynamic(dynamic_asset) => {
next_dynamics.push(dynamic_asset);
}
} }
} }
}
Ok(Vc::cell(next_dynamics)) Ok(Vc::cell(next_dynamics))
}
.instrument(tracing::info_span!("find next/dynamic references"))
.await
} }
} }
......
use anyhow::Result; use anyhow::Result;
use turbo_tasks::{Completion, Vc}; use tracing::Instrument;
use turbo_tasks::{Completion, ValueToString, Vc};
use turbo_tasks_fs::FileSystemPathOption; use turbo_tasks_fs::FileSystemPathOption;
use turbopack_binding::turbo::tasks_fs::{ use turbopack_binding::turbo::tasks_fs::{
DirectoryContent, DirectoryEntry, FileSystemEntryType, FileSystemPath, DirectoryContent, DirectoryEntry, FileSystemEntryType, FileSystemPath,
...@@ -319,61 +320,69 @@ async fn get_pages_structure_for_directory( ...@@ -319,61 +320,69 @@ async fn get_pages_structure_for_directory(
position: u32, position: u32,
page_extensions: Vc<Vec<String>>, page_extensions: Vc<Vec<String>>,
) -> Result<Vc<PagesDirectoryStructure>> { ) -> Result<Vc<PagesDirectoryStructure>> {
let page_extensions_raw = &*page_extensions.await?; let span = {
let path = project_path.to_string().await?;
tracing::info_span!("analyse pages structure", name = *path)
};
async move {
let page_extensions_raw = &*page_extensions.await?;
let mut children = vec![]; let mut children = vec![];
let mut items = vec![]; let mut items = vec![];
let dir_content = project_path.read_dir().await?; let dir_content = project_path.read_dir().await?;
if let DirectoryContent::Entries(entries) = &*dir_content { if let DirectoryContent::Entries(entries) = &*dir_content {
for (name, entry) in entries.iter() { for (name, entry) in entries.iter() {
match entry { match entry {
DirectoryEntry::File(file_project_path) => { DirectoryEntry::File(file_project_path) => {
let Some(basename) = page_basename(name, page_extensions_raw) else { let Some(basename) = page_basename(name, page_extensions_raw) else {
continue; continue;
}; };
let item_next_router_path = match basename { let item_next_router_path = match basename {
"index" => next_router_path, "index" => next_router_path,
_ => next_router_path.join(basename.to_string()), _ => next_router_path.join(basename.to_string()),
}; };
let item_original_name = next_router_path.join(basename.to_string()); let item_original_name = next_router_path.join(basename.to_string());
items.push(( items.push((
basename, basename,
PagesStructureItem::new( PagesStructureItem::new(
*file_project_path, *file_project_path,
item_next_router_path, item_next_router_path,
item_original_name, item_original_name,
), ),
)); ));
} }
DirectoryEntry::Directory(dir_project_path) => { DirectoryEntry::Directory(dir_project_path) => {
children.push(( children.push((
name, name,
get_pages_structure_for_directory( get_pages_structure_for_directory(
*dir_project_path, *dir_project_path,
next_router_path.join(name.clone()), next_router_path.join(name.clone()),
position + 1, position + 1,
page_extensions, page_extensions,
), ),
)); ));
}
_ => {}
} }
_ => {}
} }
} }
}
// Ensure deterministic order since read_dir is not deterministic // Ensure deterministic order since read_dir is not deterministic
items.sort_by_key(|(k, _)| *k); items.sort_by_key(|(k, _)| *k);
// Ensure deterministic order since read_dir is not deterministic // Ensure deterministic order since read_dir is not deterministic
children.sort_by_key(|(k, _)| *k); children.sort_by_key(|(k, _)| *k);
Ok(PagesDirectoryStructure { Ok(PagesDirectoryStructure {
project_path, project_path,
next_router_path, next_router_path,
items: items.into_iter().map(|(_, v)| v).collect(), items: items.into_iter().map(|(_, v)| v).collect(),
children: children.into_iter().map(|(_, v)| v).collect(), children: children.into_iter().map(|(_, v)| v).collect(),
}
.cell())
} }
.cell()) .instrument(span)
.await
} }
fn page_basename<'a>(name: &'a str, page_extensions: &'a [String]) -> Option<&'a str> { fn page_basename<'a>(name: &'a str, page_extensions: &'a [String]) -> Option<&'a str> {
......
...@@ -3,14 +3,32 @@ use turbopack_binding::turbopack::trace_utils::tracing_presets::{ ...@@ -3,14 +3,32 @@ use turbopack_binding::turbopack::trace_utils::tracing_presets::{
TRACING_OVERVIEW_TARGETS, TRACING_TURBOPACK_TARGETS, TRACING_TURBO_TASKS_TARGETS, TRACING_OVERVIEW_TARGETS, TRACING_TURBOPACK_TARGETS, TRACING_TURBO_TASKS_TARGETS,
}; };
pub static TRACING_NEXT_TARGETS: Lazy<Vec<&str>> = Lazy::new(|| { pub static TRACING_NEXT_OVERVIEW_TARGETS: Lazy<Vec<&str>> = Lazy::new(|| {
[ [
&TRACING_OVERVIEW_TARGETS[..], &TRACING_OVERVIEW_TARGETS[..],
&[ &[
"next_swc_napi=info",
"next_swc=info",
"next_api=info",
"next_dev=info",
"next_core=info",
"next_font=info",
"turbopack_node=info",
],
]
.concat()
});
pub static TRACING_NEXT_TARGETS: Lazy<Vec<&str>> = Lazy::new(|| {
[
&TRACING_NEXT_OVERVIEW_TARGETS[..],
&[
"next_swc_napi=trace",
"next_swc=trace",
"next_api=trace",
"next_dev=trace", "next_dev=trace",
"next_core=trace", "next_core=trace",
"next_font=trace", "next_font=trace",
"turbopack_node=trace",
], ],
] ]
.concat() .concat()
...@@ -19,7 +37,7 @@ pub static TRACING_NEXT_TURBOPACK_TARGETS: Lazy<Vec<&str>> = ...@@ -19,7 +37,7 @@ pub static TRACING_NEXT_TURBOPACK_TARGETS: Lazy<Vec<&str>> =
Lazy::new(|| [&TRACING_NEXT_TARGETS[..], &TRACING_TURBOPACK_TARGETS[..]].concat()); Lazy::new(|| [&TRACING_NEXT_TARGETS[..], &TRACING_TURBOPACK_TARGETS[..]].concat());
pub static TRACING_NEXT_TURBO_TASKS_TARGETS: Lazy<Vec<&str>> = Lazy::new(|| { pub static TRACING_NEXT_TURBO_TASKS_TARGETS: Lazy<Vec<&str>> = Lazy::new(|| {
[ [
&TRACING_TURBOPACK_TARGETS[..], &TRACING_NEXT_TURBOPACK_TARGETS[..],
&TRACING_TURBO_TASKS_TARGETS[..], &TRACING_TURBO_TASKS_TARGETS[..],
] ]
.concat() .concat()
......
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