From 1edffd6ca65305fc04f4630d74bf48f749e77ef4 Mon Sep 17 00:00:00 2001 From: Aman Karmani Date: Tue, 26 Aug 2025 09:02:05 -0700 Subject: [PATCH] feat: Expose gix-pack caching features --- gix/Cargo.toml | 18 ++++++++++++++---- gix/src/object/mod.rs | 1 + gix/src/repository/cache.rs | 9 ++++++--- gix/src/repository/init.rs | 1 + 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/gix/Cargo.toml b/gix/Cargo.toml index 38585d20ccd..deafec4d581 100644 --- a/gix/Cargo.toml +++ b/gix/Cargo.toml @@ -24,7 +24,7 @@ required-features = ["blocking-network-client"] [features] -default = ["max-performance-safe", "comfort", "basic", "extras"] +default = ["max-performance-safe", "comfort", "basic", "extras", "gix-pack-object-cache-dynamic"] #! There are various categories of features which help to optimize performance and build times. `gix` comes with 'batteries included' and everything is #! enabled as long as it doesn't sacrifice compatibility. Most users will be fine with that but will pay with higher compile times than necessary as they @@ -304,6 +304,18 @@ progress-tree = ["prodash/progress-tree"] ## Print debugging information about usage of object database caches, useful for tuning cache sizes. cache-efficiency-debug = ["gix-features/cache-efficiency-debug"] +## Control gix-pack caching behavior +## Provide a fixed-size allocation-free LRU cache for packs. It's useful if caching is desired while keeping the memory footprint +## for the LRU-cache itself low. +gix-pack-pack-cache-lru-static = ["gix-pack/pack-cache-lru-static"] + +## Control gix-pack caching behavior +## Provide a hash-map based LRU cache whose eviction is based a memory cap calculated from object data. +gix-pack-pack-cache-lru-dynamic = ["gix-pack/pack-cache-lru-dynamic"] + +## Control gix-pack caching behavior +## If set, select algorithms may additionally use a full-object cache which is queried before the pack itself. +gix-pack-object-cache-dynamic = ["gix-pack/object-cache-dynamic"] [dependencies] gix-utils = { version = "^0.3.0", path = "../gix-utils" } @@ -325,9 +337,7 @@ gix-hash = { version = "^0.19.0", path = "../gix-hash" } gix-shallow = { version = "^0.5.0", path = "../gix-shallow" } gix-object = { version = "^0.50.2", path = "../gix-object" } gix-actor = { version = "^0.35.4", path = "../gix-actor" } -gix-pack = { version = "^0.60.0", path = "../gix-pack", default-features = false, features = [ - "object-cache-dynamic", -] } +gix-pack = { version = "^0.60.0", path = "../gix-pack", default-features = false } gix-revision = { version = "^0.35.0", path = "../gix-revision", default-features = false } gix-revwalk = { version = "^0.21.0", path = "../gix-revwalk" } gix-negotiate = { version = "^0.21.0", path = "../gix-negotiate", optional = true } diff --git a/gix/src/object/mod.rs b/gix/src/object/mod.rs index d640e737d9b..fde48dab9dd 100644 --- a/gix/src/object/mod.rs +++ b/gix/src/object/mod.rs @@ -6,6 +6,7 @@ pub use gix_object::Kind; use crate::{Blob, Commit, Id, Object, ObjectDetached, Tag, Tree}; mod errors; +#[cfg(feature = "object-cache-dynamic")] pub(crate) mod cache { pub use gix_pack::cache::object::MemoryCappedHashmap; } diff --git a/gix/src/repository/cache.rs b/gix/src/repository/cache.rs index c499d6e5d41..ecf3e4f8359 100644 --- a/gix/src/repository/cache.rs +++ b/gix/src/repository/cache.rs @@ -12,9 +12,12 @@ impl crate::Repository { let bytes = bytes.into(); match bytes { Some(0) => self.objects.unset_object_cache(), - Some(bytes) => self - .objects - .set_object_cache(move || Box::new(crate::object::cache::MemoryCappedHashmap::new(bytes))), + Some(bytes) => { + #[cfg(feature = "object-cache-dynamic")] + self + .objects + .set_object_cache(move || Box::new(crate::object::cache::MemoryCappedHashmap::new(bytes))); + }, None => self.objects.unset_object_cache(), } } diff --git a/gix/src/repository/init.rs b/gix/src/repository/init.rs index 1c35b7f916b..f83684d473b 100644 --- a/gix/src/repository/init.rs +++ b/gix/src/repository/init.rs @@ -56,6 +56,7 @@ pub(crate) fn setup_objects(objects: &mut crate::OdbHandle, config: &crate::conf objects.unset_object_cache(); } else { let bytes = config.object_cache_bytes; + #[cfg(feature = "object-cache-dynamic")] objects.set_object_cache(move || Box::new(gix_pack::cache::object::MemoryCappedHashmap::new(bytes))); } }