Skip to content

Commit 63c7a03

Browse files
committed
feat: add Repository::compute_object_cache_size_for_tree_diffs().
With it it's easier to obtain reasonable object cache sizes as optimized for tree-diffs.
1 parent 26748dd commit 63c7a03

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

gix/src/object/tree/diff/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ impl<'repo> Tree<'repo> {
3333
///
3434
/// # Performance
3535
///
36-
/// It's highly recommended to set an object cache to avoid extracting the same object multiple times.
36+
/// It's highly recommended to [set an object cache](crate::Repository::compute_object_cache_size_for_tree_diffs)
37+
/// to avoid extracting the same object multiple times.
3738
/// By default, similar to `git diff`, rename tracking will be enabled if it is not configured.
3839
///
3940
/// Note that if a clone with `--filter=blob=none` was created, rename tracking may fail as it might

gix/src/repository/cache.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,15 @@ impl crate::Repository {
2727
self.object_cache_size(bytes)
2828
}
2929
}
30+
31+
/// Return the amount of bytes the object cache [should be set to](Self::object_cache_size_if_unset) to perform
32+
/// diffs between trees who are similar to `index` in a typical source code repository.
33+
///
34+
/// Currently, this allocates about 10MB for every 10k files in `index`, and a minimum of 4KB.
35+
#[cfg(feature = "index")]
36+
pub fn compute_object_cache_size_for_tree_diffs(&self, index: &gix_index::State) -> usize {
37+
let num_tracked = index.entries().len();
38+
let ten_mb_for_every_10k_files = (num_tracked as f32 / 10_000.0) * (10 * 1024 * 1024) as f32;
39+
(ten_mb_for_every_10k_files as usize).max(4 * 1024)
40+
}
3041
}

0 commit comments

Comments
 (0)