Unverified Commit e5ad31de authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

Split NFT keyed trace reads into per-module tasks

Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
parent a72565ab
...@@ -47,7 +47,7 @@ impl EndpointTraceResult { ...@@ -47,7 +47,7 @@ impl EndpointTraceResult {
.chain( .chain(
self.modules self.modules
.iter() .iter()
.map(async |m| Ok(module_data.idents.get(m).await?.unwrap().path.clone())) .map(async |m| traced_module_path(*module_data.idents, **m).owned().await)
.try_join() .try_join()
.await?, .await?,
) )
...@@ -101,11 +101,7 @@ pub async fn trace_endpoint( ...@@ -101,11 +101,7 @@ pub async fn trace_endpoint(
.iter() .iter()
.copied() .copied()
.map(async |module| { .map(async |module| {
let entry = module_paths let referenced_chunk_path = &traced_module_path(*module_paths, *module).await?;
.get(&module)
.await?
.context("missing path for module")?;
let referenced_chunk_path = &entry.path;
if referenced_chunk_path.has_extension(".map") { if referenced_chunk_path.has_extension(".map") {
return Ok(None); return Ok(None);
...@@ -417,6 +413,38 @@ pub struct TracedModuleData { ...@@ -417,6 +413,38 @@ pub struct TracedModuleData {
pub hashes: ResolvedVc<TracedModuleDataHashes>, pub hashes: ResolvedVc<TracedModuleDataHashes>,
} }
/// The traced path of a single module.
///
/// The idents map is a single task that's shared by every endpoint. Reading it once per module
/// here, instead of once per (endpoint, module), keeps every endpoint from contending on that one
/// task's lock. Endpoints read this per-module task instead, which spreads the reads across
/// modules. It still only depends on this module's key, so invalidation stays per module.
#[turbo_tasks::function]
pub async fn traced_module_path(
idents: ResolvedVc<TracedModuleDataIdents>,
module: ResolvedVc<Box<dyn Module>>,
) -> Result<Vc<FileSystemPath>> {
let ident = idents
.get(&module)
.await?
.context("missing path for module")?;
Ok(ident.path.clone().cell())
}
/// The content hash of a single traced module. See [`traced_module_path`] for why this is a
/// separate per-module task.
#[turbo_tasks::function]
pub async fn traced_module_hash(
hashes: ResolvedVc<TracedModuleDataHashes>,
module: ResolvedVc<Box<dyn Module>>,
) -> Result<Vc<RcStr>> {
let hash = hashes
.get(&module)
.await?
.context("missing hash for module")?;
Ok(Vc::cell((**hash).clone()))
}
/// This caches the paths for all modules in the graph without eagerly hashing their contents. /// This caches the paths for all modules in the graph without eagerly hashing their contents.
#[turbo_tasks::function] #[turbo_tasks::function]
async fn traced_module_idents_for_graph( async fn traced_module_idents_for_graph(
......
...@@ -15,7 +15,7 @@ use turbopack_core::{ ...@@ -15,7 +15,7 @@ use turbopack_core::{
}; };
use crate::{ use crate::{
nft::{EndpointTraceResult, tracing_exclude_glob}, nft::{EndpointTraceResult, traced_module_hash, traced_module_path, tracing_exclude_glob},
nft_json_builder::NftJsonBuilder, nft_json_builder::NftJsonBuilder,
project::Project, project::Project,
}; };
...@@ -155,22 +155,12 @@ impl Asset for NftJsonAsset { ...@@ -155,22 +155,12 @@ impl Asset for NftJsonAsset {
) )
} }
AssetOrModule::Module(v) => { AssetOrModule::Module(v) => {
let ident = module_data // Per-module tasks instead of keyed reads of the shared maps, so the
.idents // many routes don't all lock the same task (see `traced_module_path`).
.get(&v) let path = traced_module_path(*module_data.idents, *v).owned().await?;
.await? let hash = traced_module_hash(*module_data.hashes, *v).owned().await?;
.context("missing path for module")?;
let hash = module_data
.hashes
.get(&v)
.await?
.context("missing hash for module")?;
let source = v.source().await?.context("NFT module has no content")?; let source = v.source().await?.context("NFT module has no content")?;
( (path, hash, source.content().await?)
ident.path.clone(),
(**hash).clone(),
source.content().await?,
)
} }
}; };
......
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