File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments