From 66c747e611c55b63d92feedaf0330b551c7354dc Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 13 Aug 2024 16:24:43 +0200 Subject: [PATCH] somewhat fix the ODB performance bottleneck with better caching. --- crates/gitbutler-branch-actions/src/branch.rs | 5 ++--- crates/gitbutler-cli/src/command/mod.rs | 2 +- crates/gitbutler-command-context/src/lib.rs | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/crates/gitbutler-branch-actions/src/branch.rs b/crates/gitbutler-branch-actions/src/branch.rs index 3800fd9ca..e50708098 100644 --- a/crates/gitbutler-branch-actions/src/branch.rs +++ b/crates/gitbutler-branch-actions/src/branch.rs @@ -5,7 +5,7 @@ use core::fmt; use gitbutler_branch::{ Branch as GitButlerBranch, BranchId, BranchIdentity, ReferenceExtGix, Target, }; -use gitbutler_command_context::CommandContext; +use gitbutler_command_context::{CommandContext, GixRepositoryExt}; use gitbutler_reference::normalize_branch_name; use gitbutler_serde::BStringForFrontend; use gix::object::tree::diff::Action; @@ -427,8 +427,7 @@ pub fn get_branch_listing_details( .filter_map(Result::ok) .collect(); let git2_repo = ctx.repository(); - let mut repo = ctx.gix_repository_minimal()?; - repo.object_cache_size_if_unset(4 * 1024); + let repo = ctx.gix_repository_minimal()?.for_tree_diffing()?; let branches = list_branches(ctx, None, Some(branch_names))?; let (default_target_current_upstream_commit_id, default_target_seen_at_last_update) = { diff --git a/crates/gitbutler-cli/src/command/mod.rs b/crates/gitbutler-cli/src/command/mod.rs index 9645403c8..dcbb03d96 100644 --- a/crates/gitbutler-cli/src/command/mod.rs +++ b/crates/gitbutler-cli/src/command/mod.rs @@ -27,6 +27,6 @@ pub mod snapshot { } fn debug_print(this: impl std::fmt::Debug) -> anyhow::Result<()> { - eprintln!("{:#?}", this); + println!("{:#?}", this); Ok(()) } diff --git a/crates/gitbutler-command-context/src/lib.rs b/crates/gitbutler-command-context/src/lib.rs index 4326f4027..fdff7d6ba 100644 --- a/crates/gitbutler-command-context/src/lib.rs +++ b/crates/gitbutler-command-context/src/lib.rs @@ -98,3 +98,19 @@ impl CommandContext { )?) } } + +pub trait GixRepositoryExt: Sized { + /// Configure the repository for diff operations between trees. + /// This means it needs an object cache relative to the amount of files in the repository. + fn for_tree_diffing(self) -> Result; +} + +impl GixRepositoryExt for gix::Repository { + fn for_tree_diffing(mut self) -> anyhow::Result { + let num_tracked = self.index_or_empty()?.entries().len(); + let ten_mb_for_every_10k_files = + (num_tracked as f32 / 10_000.0) * (10 * 1024 * 1024) as f32; + self.object_cache_size_if_unset((ten_mb_for_every_10k_files as usize).max(4 * 1024)); + Ok(self) + } +}