Unverified Commit 8b9cdc5e authored by Jimmy Miller's avatar Jimmy Miller Committed by GitHub

perf(turbopack): skip ignored files during server tracing (#97475)

So I was playing around with profiling some very simple next apps when I
noticed this. Basically, because of how things were set up we were
spending a good chunk of our build time analyzing files we were going to
reject. I went around and around trying different combinations to make
sure we ignore those files (and only the files we should ignore) to
speed up build times. Since it is a constant impact, mostly on small
projects, but on some, it can make a big difference. I had some
adversarial rounds with agents to see if they can break the config in
the ways the old comments hints at why we didn't do that. And this final
round finally couldn't get it to break.

For a v0-generated Hello World app, compile time is 28.0% faster
(+/-1.7%) and a full clean build is 15.9% faster (+/- 1.2%).

---------
Co-authored-by: 's avatarNiklas Mischkulnig <4586894+mischnic@users.noreply.github.com>
parent 4e2abec3
This diff is collapsed.
......@@ -2682,7 +2682,7 @@ impl Project {
.await?;
let asset_context =
externals_tracing_module_context(get_tracing_compile_time_info(), false);
externals_tracing_module_context(get_tracing_compile_time_info(), false, None);
Ok(Vc::cell(
cache_handler
......@@ -2707,7 +2707,12 @@ impl Project {
/// Other endpoints use [`Project::additional_traced_modules`].
#[turbo_tasks::function]
pub async fn pages_traced_modules(self: Vc<Self>) -> Result<Vc<Modules>> {
let hook_modules = require_hook_modules(self.project_path().owned().await?)
let asset_context = Vc::upcast(externals_tracing_module_context(
get_tracing_compile_time_info(),
false,
None,
));
let hook_modules = require_hook_modules(self.project_path().owned().await?, asset_context)
.owned()
.await?;
let renderer_modules = pages_renderer_modules(self.project_path().owned().await?)
......
......@@ -140,5 +140,6 @@ pub async fn config_tracing_module_context(
.cell()
.await?,
true,
None,
)))
}
......@@ -12,13 +12,14 @@ pub mod transition;
use anyhow::{Context as _, Result, bail};
use module_options::{
ConfiguredModuleType, ModuleOptions, ModuleOptionsContext, ModuleRuleEffect, ModuleType,
ConfiguredModuleType, ModuleOptions, ModuleOptionsContext, ModuleRule, ModuleRuleEffect,
ModuleType, RuleCondition,
};
pub use runtime_asset_context::get_runtime_asset_context;
use tracing::{Instrument, field::Empty};
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, TryJoinIterExt, ValueToString, Vc};
use turbo_tasks_fs::FileSystemPath;
use turbo_tasks_fs::{FileSystemPath, glob::Glob};
pub use turbopack_core::condition;
use turbopack_core::{
asset::Asset,
......@@ -910,16 +911,30 @@ async fn process_default_internal(
Ok(module)
}
/// `prune` skips matching files as the graph is walked, rather than filtering them out of the
/// result afterwards.
#[turbo_tasks::function]
pub async fn externals_tracing_module_context(
compile_time_info: Vc<CompileTimeInfo>,
resolve_typescript: bool,
prune: Option<(FileSystemPath, ResolvedVc<Glob>)>,
) -> Result<Vc<ModuleAssetContext>> {
let mut extensions = vec![rcstr!(".js"), rcstr!(".node"), rcstr!(".json")];
if resolve_typescript {
extensions.insert(0, rcstr!(".ts"));
}
let prune_rules = match prune {
Some((base, glob)) => vec![ModuleRule::new(
RuleCondition::ResourcePathGlob {
base,
glob: glob.await?,
},
vec![ModuleRuleEffect::Ignore],
)],
None => vec![],
};
let resolve_options = ResolveOptionsContext {
custom_extensions: Some(extensions),
emulate_environment: Some(compile_time_info.await?.environment),
......@@ -957,6 +972,7 @@ pub async fn externals_tracing_module_context(
// node-file-trace.
environment: None,
analyze_mode: AnalyzeMode::Tracing,
module_rules: prune_rules,
// Disable tree shaking. Even side-effect-free imports need to be traced, as they will
// execute at runtime.
..Default::default()
......@@ -1112,6 +1128,7 @@ impl AssetContext for ModuleAssetContext {
Vc::upcast(externals_tracing_module_context(
*options.compile_time_info,
false,
None,
)),
// If target is specified, a symlink will be created to
// make the folder
......
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