Unverified Commit 7bd26a42 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Turbopack: don't treat events as relevant because their parent dir is in the watcher batch (#99782)

## Summary

On macOS, frequent writes to an untracked file kept the watcher batch
open and delayed the invalidation of tracked files until the writes
stopped. This made the native cases of
`irrelevant_events_do_not_delay_invalidation` fail consistently (took
~3.3s, i.e. the whole churn).

Why: FSEvents keeps the `ItemCreated` flag set on a recently created
file, so each write to an existing file shows up as a `Create(File)`
event. When a tracked file in the same directory changed,
`mark_parent_dir` added that directory to the batch, even though nothing
had listed it. The fast path in `is_relevant` then treated every later
`Create` of a sibling as relevant because its parent was in the batch,
and each of those events pushed the batch deadline back.

The fast path now only checks the path itself. The slow path still
checks the parent against `dir_invalidator_map`, so events under a
directory whose listing is tracked still count as relevant.

## Verification

- `cargo test -p turbo-tasks-fs --lib watcher::` on macOS: all 19 tests
pass, including `repeated_writes_to_tracked_file_are_debounced`. Before
this change, the two native
`irrelevant_events_do_not_delay_invalidation` cases failed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- NEXT_JS_LLM -->

---------
Co-authored-by: 's avatarBenjamin Woodruff <benjamin.woodruff@vercel.com>
parent b494f317
...@@ -960,15 +960,15 @@ impl BatchedInvalidations { ...@@ -960,15 +960,15 @@ impl BatchedInvalidations {
let dir_invalidator_map_guard = LazyCell::new(|| dir_invalidator_map.lock().unwrap()); let dir_invalidator_map_guard = LazyCell::new(|| dir_invalidator_map.lock().unwrap());
// If this path has no reader, we should not add it to the batch, and we should not extend // If this path has no reader, we should not add it to the batch, and we should not extend
// the batch schedule // the batch schedule. This function is best-effort and marks some events as relevant that
// will no-op.
let is_relevant = |batch: &Self, path: &Path, parent: Option<&Path>, recursive: bool| { let is_relevant = |batch: &Self, path: &Path, parent: Option<&Path>, recursive: bool| {
// fast-path: The path or parent is already in the batch, assume it is relevant // fast-path: The path is already in the batch, assume it is relevant.
if batch.paths.contains_key(path) if batch.paths.contains_key(path) {
|| parent.is_some_and(|parent| batch.paths.contains_key(parent))
{
return true; return true;
} }
// slow-path: Lock the invalidator maps, and see if they contain the path // slow-path: Lock the invalidator maps, and see if they contain the path or the parent
// (some events invalidate the parent directory)
invalidator_map_guard.contains_key(path) invalidator_map_guard.contains_key(path)
|| dir_invalidator_map_guard.contains_key(path) || dir_invalidator_map_guard.contains_key(path)
|| parent.is_some_and(|parent| dir_invalidator_map_guard.contains_key(parent)) || parent.is_some_and(|parent| dir_invalidator_map_guard.contains_key(parent))
......
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