Unverified Commit ea818580 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Turbopack: add indirection layer for better caching during resolving (#80062)

### What?

Cache the before plugin matching
parent 088bbd8d
...@@ -1700,6 +1700,24 @@ pub async fn url_resolve( ...@@ -1700,6 +1700,24 @@ pub async fn url_resolve(
.await .await
} }
#[turbo_tasks::value(transparent)]
struct MatchingBeforeResolvePlugins(Vec<ResolvedVc<Box<dyn BeforeResolvePlugin>>>);
#[turbo_tasks::function]
async fn get_matching_before_resolve_plugins(
options: Vc<ResolveOptions>,
request: Vc<Request>,
) -> Result<Vc<MatchingBeforeResolvePlugins>> {
let mut matching_plugins = Vec::new();
for &plugin in &options.await?.before_resolve_plugins {
let condition = plugin.before_resolve_condition().resolve().await?;
if *condition.matches(request).await? {
matching_plugins.push(plugin);
}
}
Ok(Vc::cell(matching_plugins))
}
#[tracing::instrument(level = "trace", skip_all)] #[tracing::instrument(level = "trace", skip_all)]
async fn handle_before_resolve_plugins( async fn handle_before_resolve_plugins(
lookup_path: FileSystemPath, lookup_path: FileSystemPath,
...@@ -1707,14 +1725,7 @@ async fn handle_before_resolve_plugins( ...@@ -1707,14 +1725,7 @@ async fn handle_before_resolve_plugins(
request: Vc<Request>, request: Vc<Request>,
options: Vc<ResolveOptions>, options: Vc<ResolveOptions>,
) -> Result<Option<Vc<ResolveResult>>> { ) -> Result<Option<Vc<ResolveResult>>> {
let options_value = options.await?; for plugin in get_matching_before_resolve_plugins(options, request).await? {
for plugin in &options_value.before_resolve_plugins {
let condition = plugin.before_resolve_condition().resolve().await?;
if !*condition.matches(request).await? {
continue;
}
if let Some(result) = *plugin if let Some(result) = *plugin
.before_resolve(lookup_path.clone(), reference_type.clone(), request) .before_resolve(lookup_path.clone(), reference_type.clone(), request)
.await? .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