fs: Replace a bunch of uses of smol::fs with manual impls (#40172)
smol::fs uses a separate threadpool, which is a bit yuck. This PR also added a benchmark you can use to run a full worktree scan (initial one, that is) for arbitrary worktree.. and refactored worktree scanner to use async locks, as otherwise tests were deadlocking. :) I've benchmarked it against Zed, Linux and Chromium and saw a ~60% drop in initial worktree scan times across the board. Release Notes: - Significantly (3.3x speedup over the old implementation) improved speed of Zed's worktree scanner, that's responsible for synchronizing the state of your project with the state of files on hard drive. --------- Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>
This commit is contained in:
co-authored by
Smit Barmase
parent
9c70ba7dcc
commit
c37a2f885a
@@ -0,0 +1,54 @@
|
||||
use std::{
|
||||
path::Path,
|
||||
sync::{Arc, atomic::AtomicUsize},
|
||||
};
|
||||
|
||||
use fs::RealFs;
|
||||
use gpui::Application;
|
||||
use settings::Settings;
|
||||
use worktree::{Worktree, WorktreeSettings};
|
||||
|
||||
fn main() {
|
||||
let Some(worktree_root_path) = std::env::args().nth(1) else {
|
||||
println!(
|
||||
"Missing path to worktree root\nUsage: bench_background_scan PATH_TO_WORKTREE_ROOT"
|
||||
);
|
||||
return;
|
||||
};
|
||||
let app = Application::headless();
|
||||
|
||||
app.run(|cx| {
|
||||
settings::init(cx);
|
||||
WorktreeSettings::register(cx);
|
||||
let fs = Arc::new(RealFs::new(None, cx.background_executor().clone()));
|
||||
|
||||
cx.spawn(async move |cx| {
|
||||
let worktree = Worktree::local(
|
||||
Path::new(&worktree_root_path),
|
||||
true,
|
||||
fs,
|
||||
Arc::new(AtomicUsize::new(0)),
|
||||
cx,
|
||||
)
|
||||
.await
|
||||
.expect("Worktree initialization to succeed");
|
||||
let did_finish_scan = worktree
|
||||
.update(cx, |this, _| this.as_local().unwrap().scan_complete())
|
||||
.unwrap();
|
||||
let start = std::time::Instant::now();
|
||||
did_finish_scan.await;
|
||||
let elapsed = start.elapsed();
|
||||
let (files, directories) = worktree
|
||||
.read_with(cx, |this, _| (this.file_count(), this.dir_count()))
|
||||
.unwrap();
|
||||
println!(
|
||||
"{:?} for {directories} directories and {files} files",
|
||||
elapsed
|
||||
);
|
||||
cx.update(|cx| {
|
||||
cx.quit();
|
||||
})
|
||||
})
|
||||
.detach();
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user