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 {
.chain(
self.modules
.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()
.await?,
)
......@@ -101,11 +101,7 @@ pub async fn trace_endpoint(
.iter()
.copied()
.map(async |module| {
let entry = module_paths
.get(&module)
.await?
.context("missing path for module")?;
let referenced_chunk_path = &entry.path;
let referenced_chunk_path = &traced_module_path(*module_paths, *module).await?;
if referenced_chunk_path.has_extension(".map") {
return Ok(None);
......@@ -417,6 +413,38 @@ pub struct TracedModuleData {
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.
#[turbo_tasks::function]
async fn traced_module_idents_for_graph(
......
......@@ -15,7 +15,7 @@ use turbopack_core::{
};
use crate::{
nft::{EndpointTraceResult, tracing_exclude_glob},
nft::{EndpointTraceResult, traced_module_hash, traced_module_path, tracing_exclude_glob},
nft_json_builder::NftJsonBuilder,
project::Project,
};
......@@ -155,22 +155,12 @@ impl Asset for NftJsonAsset {
)
}
AssetOrModule::Module(v) => {
let ident = module_data
.idents
.get(&v)
.await?
.context("missing path for module")?;
let hash = module_data
.hashes
.get(&v)
.await?
.context("missing hash for module")?;
// Per-module tasks instead of keyed reads of the shared maps, so the
// many routes don't all lock the same task (see `traced_module_path`).
let path = traced_module_path(*module_data.idents, *v).owned().await?;
let hash = traced_module_hash(*module_data.hashes, *v).owned().await?;
let source = v.source().await?.context("NFT module has no content")?;
(
ident.path.clone(),
(**hash).clone(),
source.content().await?,
)
(path, hash, 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