mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 05:51:39 +00:00
Enhance PrefetchCache and improve directory handling in VFS
- Added a `children` field to the `PrefetchCache` structure to store sorted child paths for directories, optimizing directory read operations. - Updated the `read_dir` method in `VfsInner` to utilize the new `children` cache, improving performance by reducing backend calls for cached directories. - Refactored the `prefetch_project_files` function to populate the `children` map during prefetching, enhancing the efficiency of path collection. - Adjusted tests to accommodate the new `children` field in `PrefetchCache`, ensuring comprehensive coverage of the updated functionality. These changes aim to improve the performance and reliability of the VFS by refining the prefetching mechanism and enhancing directory handling.
This commit is contained in:
parent
5a943c33ea
commit
3ccaaa63db
4 changed files with 54 additions and 5 deletions
|
|
@ -43,6 +43,8 @@ pub struct PrefetchCache {
|
|||
/// `true` = file, `false` = directory. Paths not in the map fall through
|
||||
/// to the backend (e.g. init-file probes for paths that don't exist).
|
||||
pub is_file: HashMap<PathBuf, bool>,
|
||||
/// Directory path -> sorted child paths. Consumed once per directory.
|
||||
pub children: HashMap<PathBuf, Vec<PathBuf>>,
|
||||
}
|
||||
|
||||
mod sealed {
|
||||
|
|
@ -216,6 +218,19 @@ impl VfsInner {
|
|||
|
||||
fn read_dir<P: AsRef<Path>>(&mut self, path: P) -> io::Result<ReadDir> {
|
||||
let path = path.as_ref();
|
||||
|
||||
if let Some(cache) = &mut self.prefetch_cache {
|
||||
if let Some(child_paths) = cache.children.remove(path) {
|
||||
if self.watch_enabled {
|
||||
self.backend.watch(path)?;
|
||||
}
|
||||
let inner = child_paths.into_iter().map(|p| Ok(DirEntry { path: p }));
|
||||
return Ok(ReadDir {
|
||||
inner: Box::new(inner),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let dir = self.backend.read_dir(path)?;
|
||||
|
||||
if self.watch_enabled {
|
||||
|
|
@ -765,6 +780,7 @@ mod test {
|
|||
.map(|(k, v)| (PathBuf::from(k), PathBuf::from(v)))
|
||||
.collect(),
|
||||
is_file: HashMap::new(),
|
||||
children: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -883,6 +899,7 @@ mod test {
|
|||
files: cache_files,
|
||||
canonical: HashMap::new(),
|
||||
is_file: HashMap::new(),
|
||||
children: HashMap::new(),
|
||||
});
|
||||
|
||||
let result = vfs.read(&file_path).unwrap();
|
||||
|
|
@ -954,6 +971,7 @@ mod test {
|
|||
files: cache_files,
|
||||
canonical: HashMap::new(),
|
||||
is_file: HashMap::new(),
|
||||
children: HashMap::new(),
|
||||
});
|
||||
|
||||
let handles: Vec<_> = (0..100)
|
||||
|
|
@ -998,6 +1016,7 @@ mod test {
|
|||
files: cache_files,
|
||||
canonical,
|
||||
is_file: HashMap::new(),
|
||||
children: HashMap::new(),
|
||||
});
|
||||
|
||||
for i in 0..50 {
|
||||
|
|
|
|||
|
|
@ -82,6 +82,11 @@ impl StdBackend {
|
|||
);
|
||||
false // keep watcher running
|
||||
}
|
||||
WatcherCriticalError::ChannelSendFailed(_) => {
|
||||
// The event receiver was dropped (VFS shutdown). This is
|
||||
// normal during process exit -- stop the thread silently.
|
||||
true
|
||||
}
|
||||
_ => {
|
||||
log::error!("{}. File watching is no longer reliable.", err);
|
||||
std::process::exit(1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue