mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
Always read files to string on a background thread (#9341)
We noticed that when you open a lot of files (i.e. project-wide search with multi-buffer) that the main thread can become unresponsive, because while we are async, we still load these files on the main thread. What this change does is it uses `smol::unblock` to load files on a different thread. Release Notes: - Improved responsiveness when loading files into memory. Co-authored-by: Antonio <antonio@zed.dev> Co-authored-by: Kirill <kirill@zed.dev>
This commit is contained in:
parent
c015baa638
commit
7629c16162
@ -214,12 +214,9 @@ impl Fs for RealFs {
|
||||
}
|
||||
|
||||
async fn load(&self, path: &Path) -> Result<String> {
|
||||
let mut file = smol::fs::File::open(path).await?;
|
||||
// We use `read_exact` here instead of `read_to_string` as the latter is *very*
|
||||
// happy to reallocate often, which comes into play when we're loading large files.
|
||||
let mut storage = vec![0; file.metadata().await?.len() as usize];
|
||||
file.read_exact(&mut storage).await?;
|
||||
Ok(String::from_utf8(storage)?)
|
||||
let path = path.to_path_buf();
|
||||
let text = smol::unblock(|| std::fs::read_to_string(path)).await?;
|
||||
Ok(text)
|
||||
}
|
||||
|
||||
async fn atomic_write(&self, path: PathBuf, data: String) -> Result<()> {
|
||||
|
Loading…
Reference in New Issue
Block a user