Skip to content

Commit cd74470

Browse files
committed
perf(source): Don't du on every git source load
When profiling Zed (#14238), a major factor in their no-op run times is git patches and git dependencies. The slowest operation for each git source is running `du`. This is extraneous for a couple of reasons - GC isn't stable, slowing people down for a feature they aren't using - Size tracking was expected to be lazy, only reading sizes when the GC is configured for size, while this was eager - Git checkouts are immutable but we check on every load - This optimized for "while filesystem caches are warm" from a checkout operation when checkout operations are rare compared to all of the other commands run on a working directory. This removes the `du`, relying on the lazy loading that happens in `update_null_sizes`.
1 parent 2d658f2 commit cd74470

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

src/cargo/core/global_cache_tracker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1800,7 +1800,7 @@ pub fn is_silent_error(e: &anyhow::Error) -> bool {
18001800

18011801
/// Returns the disk usage for a git checkout directory.
18021802
#[tracing::instrument]
1803-
pub fn du_git_checkout(path: &Path) -> CargoResult<u64> {
1803+
fn du_git_checkout(path: &Path) -> CargoResult<u64> {
18041804
// !.git is used because clones typically use hardlinks for the git
18051805
// contents. TODO: Verify behavior on Windows.
18061806
// TODO: Or even better, switch to worktrees, and remove this.

src/cargo/sources/git/source.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,13 @@ impl<'gctx> GitSource<'gctx> {
145145
self.path_source.as_mut().unwrap().read_packages()
146146
}
147147

148-
fn mark_used(&self, size: Option<u64>) -> CargoResult<()> {
148+
fn mark_used(&self) -> CargoResult<()> {
149149
self.gctx
150150
.deferred_global_last_use()?
151151
.mark_git_checkout_used(global_cache_tracker::GitCheckout {
152152
encoded_git_name: self.ident,
153153
short_name: self.short_id.expect("update before download"),
154-
size,
154+
size: None,
155155
});
156156
Ok(())
157157
}
@@ -268,7 +268,7 @@ impl<'gctx> Source for GitSource<'gctx> {
268268

269269
fn block_until_ready(&mut self) -> CargoResult<()> {
270270
if self.path_source.is_some() {
271-
self.mark_used(None)?;
271+
self.mark_used()?;
272272
return Ok(());
273273
}
274274

@@ -363,11 +363,7 @@ impl<'gctx> Source for GitSource<'gctx> {
363363
self.locked_rev = Revision::Locked(actual_rev);
364364
self.path_source.as_mut().unwrap().load()?;
365365

366-
// Hopefully this shouldn't incur too much of a performance hit since
367-
// most of this should already be in cache since it was just
368-
// extracted.
369-
let size = global_cache_tracker::du_git_checkout(&checkout_path)?;
370-
self.mark_used(Some(size))?;
366+
self.mark_used()?;
371367
Ok(())
372368
}
373369

@@ -377,7 +373,7 @@ impl<'gctx> Source for GitSource<'gctx> {
377373
id,
378374
self.remote
379375
);
380-
self.mark_used(None)?;
376+
self.mark_used()?;
381377
self.path_source
382378
.as_mut()
383379
.expect("BUG: `update()` must be called before `get()`")

0 commit comments

Comments
 (0)