Commit f7b559a6 authored by Luke Sandberg's avatar Luke Sandberg Committed by Luke Sandberg

Remove `is_export_missing` as a turbo task

In a build of vercel-site we see 70991 executions and 163683 cache hits which implies each execution gets 2.3 cache hits.  By removing turbo tasks we instead have this logic execute in the parent task `EsmAssetReference::resolve_reference`

Based on examining a trace of vercel-site i see that this task takes around 0.2-0.5us  of cpu time, but between 4-6us of 'extent'.    The `overhead.rs` benchmark tells me that the cost of a cache hit is around 220-500ns and the cost of a miss is 4.5-6us.

So, in terms of latency, we can compute expected costs
* as a turbotask:
     * lower bound: 4.5+4 + 2.3*.22 = 9.006us
     * upper bound: 6+6 + 2.3*.5 = 13.5us
* as an `async fn`
     *  lower bound: 3.3*4 = 13.2us
      * upper bound: 3.3*6 = 19.8us
parent f9de66e4
......@@ -454,7 +454,7 @@ impl ModuleReference for EsmAssetReference {
if let Some(ModulePart::Export(export_name)) = &self.export_name {
for &module in result.primary_modules().await? {
if let Some(module) = ResolvedVc::try_downcast(module)
&& *is_export_missing(*module, export_name.clone()).await?
&& is_export_missing(module, export_name.as_str()).await?
{
InvalidExport {
export: export_name.clone(),
......
......@@ -71,41 +71,41 @@ pub enum EsmExport {
Error,
}
#[turbo_tasks::function]
/// Returns true if the export is missing from the module.
pub async fn is_export_missing(
module: ResolvedVc<Box<dyn EcmascriptChunkPlaceable>>,
export_name: RcStr,
) -> Result<Vc<bool>> {
export_name: &str,
) -> Result<bool> {
if export_name == "__turbopack_module_id__" {
return Ok(Vc::cell(false));
return Ok(false);
}
let exports = module.get_exports().await?;
let exports = match &*exports {
EcmascriptExports::None => return Ok(Vc::cell(true)),
EcmascriptExports::Unknown => return Ok(Vc::cell(false)),
EcmascriptExports::Value => return Ok(Vc::cell(false)),
EcmascriptExports::CommonJs => return Ok(Vc::cell(false)),
EcmascriptExports::EmptyCommonJs => return Ok(Vc::cell(export_name != "default")),
EcmascriptExports::DynamicNamespace => return Ok(Vc::cell(false)),
EcmascriptExports::None => return Ok(true),
EcmascriptExports::Unknown => return Ok(false),
EcmascriptExports::Value => return Ok(false),
EcmascriptExports::CommonJs => return Ok(false),
EcmascriptExports::EmptyCommonJs => return Ok(export_name != "default"),
EcmascriptExports::DynamicNamespace => return Ok(false),
EcmascriptExports::EsmExports(exports) => *exports,
};
let exports = exports.await?;
if exports.exports.contains_key(&export_name) {
return Ok(Vc::cell(false));
if exports.exports.contains_key(export_name) {
return Ok(false);
}
if export_name == "default" {
return Ok(Vc::cell(true));
return Ok(true);
}
if exports.star_exports.is_empty() {
return Ok(Vc::cell(true));
return Ok(true);
}
let all_export_names = get_all_export_names(*module).await?;
if all_export_names.esm_exports.contains_key(&export_name) {
return Ok(Vc::cell(false));
if all_export_names.esm_exports.contains_key(export_name) {
return Ok(false);
}
for &dynamic_module in &all_export_names.dynamic_exporting_modules {
......@@ -115,7 +115,7 @@ pub async fn is_export_missing(
| EcmascriptExports::CommonJs
| EcmascriptExports::DynamicNamespace
| EcmascriptExports::Unknown => {
return Ok(Vc::cell(false));
return Ok(false);
}
EcmascriptExports::None
| EcmascriptExports::EmptyCommonJs
......@@ -123,7 +123,7 @@ pub async fn is_export_missing(
}
}
Ok(Vc::cell(true))
Ok(true)
}
#[turbo_tasks::function]
......
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