From 0fb5c8776e5aa4663583f37580e3d50b365c0002 Mon Sep 17 00:00:00 2001 From: Joe Date: Fri, 6 Mar 2026 18:25:21 -0600 Subject: [PATCH] Refactor VFS watching mechanism for improved performance - Replaced the selective watching logic with a more efficient recursive watching setup in the `ServeSession` implementation. - Enhanced logging to include the number of recursive watches set up and the elapsed time for the setup process, providing better insights into performance. - Removed the previous recorded paths logic to streamline the watching process. These changes aim to optimize the VFS's directory watching capabilities and improve monitoring during the setup phase. --- src/serve_session.rs | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/src/serve_session.rs b/src/serve_session.rs index 587f2456..cb7c8c9f 100644 --- a/src/serve_session.rs +++ b/src/serve_session.rs @@ -291,8 +291,22 @@ impl ServeSession { let mut instance_context = InstanceContext::new(); instance_context.sync_scripts_only = sync_scripts_only; - vfs.set_watch_recursive(false); - vfs.start_watch_recording(); + let watch_start = Instant::now(); + let mut path_roots = Vec::new(); + collect_path_roots( + &root_project.tree, + root_project.folder_location(), + &mut path_roots, + ); + let _ = vfs.watch(root_project.folder_location()); + for root in &path_roots { + let _ = vfs.watch(root); + } + log::debug!( + "Set up {} recursive watches in {:.1?}", + path_roots.len() + 1, + watch_start.elapsed(), + ); let snap_start = Instant::now(); log::trace!("Generating snapshot of instances from VFS"); @@ -309,30 +323,6 @@ impl ServeSession { apply_patch_set(&mut tree, patch_set); log::debug!("Patch computed + applied in {:.1?}", patch_start.elapsed()); - let watch_start = Instant::now(); - if let Some(recorded_paths) = vfs.take_recorded_paths() { - let dir_count = recorded_paths.iter().filter(|p| p.is_dir()).count(); - for path in &recorded_paths { - if path.is_dir() { - let _ = vfs.watch(path); - } - } - let mut path_roots = Vec::new(); - collect_path_roots( - &root_project.tree, - root_project.folder_location(), - &mut path_roots, - ); - for root in &path_roots { - let _ = vfs.watch(root); - } - log::debug!( - "Selective watching: {} directories watched (non-recursive) in {:.1?}", - dir_count + path_roots.len(), - watch_start.elapsed(), - ); - } - Ok((root_project, tree)) }