Unverified Commit 70c0a66c authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Turbopack: use raw_read_dir to create fewer FileSystemPaths (#75237)

### What?

* use raw_read_dir to avoid creating many FileSystemPaths
* use raw_read_dir in resolving
parent 7a36a464
use anyhow::{bail, Result};
use auto_hash_map::AutoMap;
use turbo_rcstr::RcStr;
use turbo_tasks::{Completion, ResolvedVc, ValueToString, Vc};
use crate::{
DirectoryContent, DirectoryEntry, FileContent, FileMeta, FileSystem, FileSystemPath,
LinkContent,
};
use crate::{FileContent, FileMeta, FileSystem, FileSystemPath, LinkContent, RawDirectoryContent};
/// A wrapper [FileSystem] which attaches a child [FileSystem] as a
/// "subdirectory" in the given root [FileSystem].
......@@ -133,29 +129,8 @@ impl FileSystem for AttachedFileSystem {
}
#[turbo_tasks::function(fs)]
async fn read_dir(self: Vc<Self>, path: Vc<FileSystemPath>) -> Result<Vc<DirectoryContent>> {
let dir_content = self.get_inner_fs_path(path).read_dir().await?;
let entries = match &*dir_content {
DirectoryContent::Entries(e) => e,
DirectoryContent::NotFound => return Ok(DirectoryContent::not_found()),
};
let mut converted_entries = AutoMap::with_capacity(entries.len());
for (name, entry) in entries {
use DirectoryEntry::*;
let entry = match *entry {
File(path) => File(self.convert_path(*path).to_resolved().await?),
Directory(path) => Directory(self.convert_path(*path).to_resolved().await?),
Symlink(path) => Symlink(self.convert_path(*path).to_resolved().await?),
Other(path) => Other(self.convert_path(*path).to_resolved().await?),
Error => Error,
};
converted_entries.insert(name.clone(), entry);
}
Ok(DirectoryContent::new(converted_entries))
fn raw_read_dir(self: Vc<Self>, path: Vc<FileSystemPath>) -> Vc<RawDirectoryContent> {
self.get_inner_fs_path(path).raw_read_dir()
}
#[turbo_tasks::function(fs)]
......
......@@ -5,8 +5,8 @@ use turbo_rcstr::RcStr;
use turbo_tasks::{Completion, ValueToString, Vc};
use crate::{
DirectoryContent, DirectoryEntry, File, FileContent, FileMeta, FileSystem, FileSystemPath,
LinkContent,
File, FileContent, FileMeta, FileSystem, FileSystemPath, LinkContent, RawDirectoryContent,
RawDirectoryEntry,
};
#[turbo_tasks::value(serialization = "none", cell = "new", eq = "manual")]
......@@ -40,12 +40,12 @@ impl FileSystem for EmbeddedFileSystem {
}
#[turbo_tasks::function]
async fn read_dir(&self, path: Vc<FileSystemPath>) -> Result<Vc<DirectoryContent>> {
async fn raw_read_dir(&self, path: Vc<FileSystemPath>) -> Result<Vc<RawDirectoryContent>> {
let path_str = &path.await?.path;
let dir = match (path_str.as_str(), self.dir.get_dir(path_str)) {
("", _) => self.dir,
(_, Some(dir)) => dir,
(_, None) => return Ok(DirectoryContent::NotFound.cell()),
(_, None) => return Ok(RawDirectoryContent::NotFound.cell()),
};
let mut converted_entries = AutoMap::new();
......@@ -56,18 +56,17 @@ impl FileSystem for EmbeddedFileSystem {
.unwrap_or_default()
.to_string_lossy()
.into();
let entry_path = path.join(entry_name.clone()).to_resolved().await?;
converted_entries.insert(
entry_name,
match e {
DirEntry::Dir(_) => DirectoryEntry::Directory(entry_path),
DirEntry::File(_) => DirectoryEntry::File(entry_path),
DirEntry::Dir(_) => RawDirectoryEntry::Directory,
DirEntry::File(_) => RawDirectoryEntry::File,
},
);
}
Ok(DirectoryContent::new(converted_entries))
Ok(RawDirectoryContent::new(converted_entries))
}
#[turbo_tasks::function]
......
This diff is collapsed.
......@@ -2,7 +2,8 @@ use anyhow::{bail, Result};
use turbo_rcstr::RcStr;
use turbo_tasks::{Completion, ValueDefault, ValueToString, Vc};
use super::{DirectoryContent, FileContent, FileMeta, FileSystem, FileSystemPath, LinkContent};
use super::{FileContent, FileMeta, FileSystem, FileSystemPath, LinkContent};
use crate::RawDirectoryContent;
#[turbo_tasks::value]
pub struct VirtualFileSystem {
......@@ -56,7 +57,7 @@ impl FileSystem for VirtualFileSystem {
}
#[turbo_tasks::function]
fn read_dir(&self, _fs_path: Vc<FileSystemPath>) -> Result<Vc<DirectoryContent>> {
fn raw_read_dir(&self, _fs_path: Vc<FileSystemPath>) -> Result<Vc<RawDirectoryContent>> {
bail!("Reading is not possible on the virtual file system")
}
......
......@@ -2,7 +2,7 @@ use anyhow::{bail, Result};
use turbo_rcstr::RcStr;
use turbo_tasks::{Completion, ValueToString, Vc};
use turbo_tasks_fs::{
DirectoryContent, FileContent, FileMeta, FileSystem, FileSystemPath, LinkContent,
FileContent, FileMeta, FileSystem, FileSystemPath, LinkContent, RawDirectoryContent,
};
#[turbo_tasks::value]
......@@ -29,7 +29,7 @@ impl FileSystem for ServerFileSystem {
}
#[turbo_tasks::function]
fn read_dir(&self, _fs_path: Vc<FileSystemPath>) -> Result<Vc<DirectoryContent>> {
fn raw_read_dir(&self, _fs_path: Vc<FileSystemPath>) -> Result<Vc<RawDirectoryContent>> {
bail!("Reading is not possible from the marker filesystem for the server")
}
......
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