Skip to content

Commit 62bd65b

Browse files
committed
Conditionally track webpack loader dependencies based on whether or not we are tracking any dependencies
1 parent 389d771 commit 62bd65b

File tree

5 files changed

+63
-41
lines changed

5 files changed

+63
-41
lines changed

turbopack/crates/turbo-tasks-backend/src/backend/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3104,6 +3104,10 @@ impl<B: BackingStorage> Backend for TurboTasksBackend<B> {
31043104
fn task_statistics(&self) -> &TaskStatisticsApi {
31053105
&self.0.task_statistics
31063106
}
3107+
3108+
fn is_tracking_dependencies(&self) -> bool {
3109+
self.0.options.dependency_tracking
3110+
}
31073111
}
31083112

31093113
enum DebugTraceTransientTask {

turbopack/crates/turbo-tasks-testing/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,10 @@ impl TurboTasksApi for VcStorage {
324324
fn send_compilation_event(&self, _event: Arc<dyn CompilationEvent>) {
325325
unimplemented!()
326326
}
327+
328+
fn is_tracking_dependencies(&self) -> bool {
329+
false
330+
}
327331
}
328332

329333
impl VcStorage {

turbopack/crates/turbo-tasks/src/backend.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,4 +728,6 @@ pub trait Backend: Sync + Send {
728728
fn dispose_root_task(&self, task: TaskId, turbo_tasks: &dyn TurboTasksBackendApi<Self>);
729729

730730
fn task_statistics(&self) -> &TaskStatisticsApi;
731+
732+
fn is_tracking_dependencies(&self) -> bool;
731733
}

turbopack/crates/turbo-tasks/src/manager.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ pub trait TurboTasksApi: TurboTasksCallApi + Sync + Send {
202202
event_types: Option<Vec<String>>,
203203
) -> Receiver<Arc<dyn CompilationEvent>>;
204204
fn send_compilation_event(&self, event: Arc<dyn CompilationEvent>);
205+
206+
// Returns true if TurboTasks is configured to track dependencies.
207+
fn is_tracking_dependencies(&self) -> bool;
205208
}
206209

207210
/// A wrapper around a value that is unused.
@@ -1442,6 +1445,10 @@ impl<B: Backend + 'static> TurboTasksApi for TurboTasks<B> {
14421445
tracing::warn!("Failed to send compilation event: {e}");
14431446
}
14441447
}
1448+
1449+
fn is_tracking_dependencies(&self) -> bool {
1450+
self.backend.is_tracking_dependencies()
1451+
}
14451452
}
14461453

14471454
impl<B: Backend + 'static> TurboTasksBackendApi<B> for TurboTasks<B> {

turbopack/crates/turbopack-node/src/transforms/webpack.rs

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -497,48 +497,53 @@ impl EvaluateContext for WebpackLoaderContext {
497497
directories,
498498
build_file_paths,
499499
} => {
500-
// Track dependencies of the loader task
501-
// TODO: Because these are reported _after_ the loader actually read the dependency
502-
// there is a race condition where we may miss updates that race
503-
// with the loader execution.
504-
505-
// Track all the subscriptions in parallel, since certain loaders like tailwind
506-
// might add thousands of subscriptions.
507-
let env_subscriptions = env_variables
508-
.iter()
509-
.map(|e| self.env.read(e.clone()))
510-
.try_join();
511-
let file_subscriptions = file_paths
512-
.iter()
513-
.map(|p| async move { self.cwd.join(p)?.read().await })
514-
.try_join();
515-
let directory_subscriptions = directories
516-
.iter()
517-
.map(|(dir, glob)| async move {
518-
self.cwd
519-
.join(dir)?
520-
.track_glob(Glob::new(glob.clone(), GlobOptions::default()), false)
521-
.await
522-
})
523-
.try_join();
524-
let build_paths = build_file_paths
525-
.iter()
526-
.map(|path| async move { self.cwd.join(path) })
527-
.try_join();
528-
let (resolved_build_paths, ..) = try_join!(
529-
build_paths,
530-
env_subscriptions,
531-
file_subscriptions,
532-
directory_subscriptions
533-
)?;
534-
535-
for build_path in resolved_build_paths {
536-
BuildDependencyIssue {
537-
source: IssueSource::from_source_only(self.context_source_for_issue),
538-
path: build_path,
500+
// We only process these dependencies to help with tracking, so if it is disabled
501+
// dont bother.
502+
if turbo_tasks::turbo_tasks().is_tracking_dependencies() {
503+
// Track dependencies of the loader task
504+
// TODO: Because these are reported _after_ the loader actually read the
505+
// dependency there is a race condition where we may miss
506+
// updates that race with the loader execution.
507+
508+
// Track all the subscriptions in parallel, since certain loaders like tailwind
509+
// might add thousands of subscriptions.
510+
let env_subscriptions = env_variables
511+
.iter()
512+
.map(|e| self.env.read(e.clone()))
513+
.try_join();
514+
let file_subscriptions = file_paths
515+
.iter()
516+
.map(|p| async move { self.cwd.join(p)?.read().await })
517+
.try_join();
518+
let directory_subscriptions = directories
519+
.iter()
520+
.map(|(dir, glob)| async move {
521+
self.cwd
522+
.join(dir)?
523+
.track_glob(Glob::new(glob.clone(), GlobOptions::default()), false)
524+
.await
525+
})
526+
.try_join();
527+
let build_paths = build_file_paths
528+
.iter()
529+
.map(|path| async move { self.cwd.join(path) })
530+
.try_join();
531+
let (resolved_build_paths, ..) = try_join!(
532+
build_paths,
533+
env_subscriptions,
534+
file_subscriptions,
535+
directory_subscriptions
536+
)?;
537+
538+
// These are 'build-dependency' messages from PostCss.
539+
for build_path in resolved_build_paths {
540+
BuildDependencyIssue {
541+
source: IssueSource::from_source_only(self.context_source_for_issue),
542+
path: build_path,
543+
}
544+
.resolved_cell()
545+
.emit();
539546
}
540-
.resolved_cell()
541-
.emit();
542547
}
543548
}
544549
InfoMessage::EmittedError { error, severity } => {

0 commit comments

Comments
 (0)