Skip to content

Commit

Permalink
feat: object cache size is configurable (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Sep 21, 2021
1 parent 741558d commit 5a8c2da
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
20 changes: 19 additions & 1 deletion git-pack/src/data/output/count/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pub fn objects<Find, Iter, IterErr, Oid, Cache>(
thread_limit,
input_object_expansion,
chunk_size,
#[cfg(feature = "object-cache-dynamic")]
object_cache_size_in_bytes,
}: Options,
) -> Result<find::existing::Error<Find::Error>, IterErr>
where
Expand Down Expand Up @@ -94,6 +96,8 @@ where
progress,
should_interrupt,
true,
#[cfg(feature = "object-cache-dynamic")]
object_cache_size_in_bytes,
)
}
},
Expand All @@ -109,6 +113,7 @@ pub fn objects_unthreaded<Find, IterErr, Oid>(
mut progress: impl Progress,
should_interrupt: &AtomicBool,
input_object_expansion: ObjectExpansion,
#[cfg(feature = "object-cache-dynamic")] object_cache_size_in_bytes: usize,
) -> Result<find::existing::Error<Find::Error>, IterErr>
where
Find: crate::Find + Send + Sync,
Expand All @@ -129,6 +134,8 @@ where
&mut progress,
should_interrupt,
false,
#[cfg(feature = "object-cache-dynamic")]
object_cache_size_in_bytes,
)
}

Expand All @@ -144,6 +151,7 @@ fn expand_inner<Find, IterErr, Oid>(
progress: &mut impl Progress,
should_interrupt: &AtomicBool,
allow_pack_lookups: bool,
#[cfg(feature = "object-cache-dynamic")] object_cache_size_in_bytes: usize,
) -> Result<find::existing::Error<Find::Error>, IterErr>
where
Find: crate::Find + Send + Sync,
Expand All @@ -160,7 +168,7 @@ where
let mut changes_delegate = tree::changes::AllNew::new(seen_objs);
let mut outcome = Outcome::default();
#[cfg(feature = "object-cache-dynamic")]
let mut obj_cache = crate::cache::object::MemoryCappedHashmap::new(10 * 1024 * 1024); // TODO: make configurable
let mut obj_cache = crate::cache::object::MemoryCappedHashmap::new(object_cache_size_in_bytes);
#[cfg(not(feature = "object-cache-dynamic"))]
let mut obj_cache = crate::cache::object::Never;

Expand Down Expand Up @@ -637,6 +645,14 @@ mod types {
pub chunk_size: usize,
/// The way input objects are handled
pub input_object_expansion: ObjectExpansion,
/// The size of a per-thread object cache in bytes to accelerate tree diffs in conjunction
/// with [ObjectExpansion::TreeAdditionsComparedToAncestor].
///
/// If zero, the cache is disabled but in a costly way. Consider using a low value instead.
///
/// Defaults to 10 megabytes which usually leads to 2.5x speedups.
#[cfg(feature = "object-cache-dynamic")]
pub object_cache_size_in_bytes: usize,
}

impl Default for Options {
Expand All @@ -645,6 +661,8 @@ mod types {
thread_limit: None,
chunk_size: 10,
input_object_expansion: Default::default(),
#[cfg(feature = "object-cache-dynamic")]
object_cache_size_in_bytes: 10 * 1024 * 1024,
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions gitoxide-core/src/pack/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ where
};
let progress = progress::ThroughputOnDrop::new(progress);
let input_object_expansion = expansion.into();
let total_object_cache_size = 50 * 1024 * 1024; // TODO: make configurable
let (mut counts, count_stats) = if may_use_multiple_threads {
pack::data::output::count::objects(
Arc::clone(&odb),
Expand All @@ -186,6 +187,7 @@ where
thread_limit,
chunk_size,
input_object_expansion,
object_cache_size_in_bytes: total_object_cache_size / thread_limit.unwrap_or(1),
},
)?
} else {
Expand All @@ -196,6 +198,7 @@ where
progress,
&interrupt::IS_INTERRUPTED,
input_object_expansion,
total_object_cache_size,
)?
};
stats.counts = count_stats;
Expand Down

0 comments on commit 5a8c2da

Please sign in to comment.