somewhat fix the ODB performance bottleneck with better caching.

This commit is contained in:
Sebastian Thiel 2024-08-13 16:24:43 +02:00
parent a2382bde74
commit 66c747e611
No known key found for this signature in database
GPG Key ID: 9CB5EE7895E8268B
3 changed files with 19 additions and 4 deletions

View File

@ -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) = {

View File

@ -27,6 +27,6 @@ pub mod snapshot {
}
fn debug_print(this: impl std::fmt::Debug) -> anyhow::Result<()> {
eprintln!("{:#?}", this);
println!("{:#?}", this);
Ok(())
}

View File

@ -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<Self>;
}
impl GixRepositoryExt for gix::Repository {
fn for_tree_diffing(mut self) -> anyhow::Result<Self> {
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)
}
}