Skip to content

Commit

Permalink
Remove support for keeping compressed memory to reduce the index size
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Aug 4, 2020
1 parent 2bb6fd2 commit 1e2ec7e
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 35 deletions.
5 changes: 1 addition & 4 deletions git-odb/src/pack/index/write/consume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,9 @@ where
entry.decompressed_size as usize,
)?
}
Mode::InMemoryDecompressed | Mode::InMemory => {
unreachable!("BUG: If there is no cache, we always need a resolver")
}
Mode::InMemory => unreachable!("BUG: If there is no cache, we always need a resolver"),
}
}
Cache::Compressed(bytes, decompressed_len) => decompress_all_at_once(&bytes, decompressed_len)?,
Cache::Decompressed(bytes) => bytes,
})
};
Expand Down
4 changes: 2 additions & 2 deletions git-odb/src/pack/index/write/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl pack::index::File {
entry_len,
kind: ObjectKind::Base(header.to_kind().expect("a base object")),
crc32,
cache: mode.base_cache(compressed, decompressed),
cache: mode.base_cache(decompressed),
},
)?;
}
Expand All @@ -98,7 +98,7 @@ impl pack::index::File {
entry_len,
kind: ObjectKind::OfsDelta,
crc32,
cache: mode.delta_cache(compressed, decompressed),
cache: mode.delta_cache(decompressed),
},
)?;
}
Expand Down
21 changes: 8 additions & 13 deletions git-odb/src/pack/index/write/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ pub struct Outcome {
pub(crate) enum Cache {
Unset,
Decompressed(Vec<u8>),
/// compressed bytes + decompressed size
Compressed(Vec<u8>, usize),
}

impl Default for Cache {
Expand Down Expand Up @@ -67,34 +65,31 @@ pub type EntrySlice = std::ops::Range<u64>;
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
pub enum Mode {
/// Base + deltas in memory compressed
/// Base + deltas in memory, decompressed
InMemory,
InMemoryDecompressed,
/// Deltas in memory compressed
/// Deltas in memory, decompressed
ResolveBases,
/// Bases in memory compressed
/// Bases in memory, decompressed
ResolveDeltas,
ResolveBasesAndDeltas,
}

impl Mode {
pub(crate) fn base_cache(&self, compressed: Vec<u8>, decompressed: Vec<u8>) -> Cache {
pub(crate) fn base_cache(&self, decompressed: Vec<u8>) -> Cache {
match self {
Mode::ResolveDeltas | Mode::InMemory => Cache::Compressed(compressed, decompressed.len()),
Mode::InMemoryDecompressed => Cache::Decompressed(decompressed),
Mode::InMemory | Mode::ResolveDeltas => Cache::Decompressed(decompressed),
Mode::ResolveBases | Mode::ResolveBasesAndDeltas => Cache::Unset,
}
}
pub(crate) fn delta_cache(&self, compressed: Vec<u8>, decompressed: Vec<u8>) -> Cache {
pub(crate) fn delta_cache(&self, decompressed: Vec<u8>) -> Cache {
match self {
Mode::ResolveBases | Mode::InMemory => Cache::Compressed(compressed, decompressed.len()),
Mode::InMemoryDecompressed => Cache::Decompressed(decompressed),
Mode::ResolveBases | Mode::InMemory => Cache::Decompressed(decompressed),
Mode::ResolveDeltas | Mode::ResolveBasesAndDeltas => Cache::Unset,
}
}
pub(crate) fn is_in_memory(&self) -> bool {
match self {
Mode::InMemory | Mode::InMemoryDecompressed => true,
Mode::InMemory => true,
Mode::ResolveBases | Mode::ResolveDeltas | Mode::ResolveBasesAndDeltas => false,
}
}
Expand Down
7 changes: 0 additions & 7 deletions git-odb/tests/pack/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,6 @@ mod method {
pack::index::write::Mode::noop_resolver()?,
pack::index::write::Mode::InMemory,
)?;
assert_index_write(
mode,
index_path,
data_path,
pack::index::write::Mode::noop_resolver()?,
pack::index::write::Mode::InMemoryDecompressed,
)?;
}
}
Ok(())
Expand Down
4 changes: 1 addition & 3 deletions git-odb/tests/pack/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ fn using_option_as_data_does_not_increase_size_in_memory() {
enum Cache {
_Unset,
_Decompressed(Vec<u8>),
// compressed bytes + decompressed size
_Compressed(Vec<u8>, usize),
}
enum ObjectKind {
_Base(git_object::Kind),
Expand Down Expand Up @@ -36,7 +34,7 @@ fn using_option_as_data_does_not_increase_size_in_memory() {
);
assert_eq!(
std::mem::size_of::<[TreeItemOption<Entry>; 7_500_000]>(),
900000000,
780000000,
"it should be as small as possible"
);
}
3 changes: 0 additions & 3 deletions gitoxide-core/src/pack/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ impl From<IterationMode> for pack::data::iter::Mode {
#[derive(PartialEq, Debug)]
pub enum MemoryMode {
InMemory,
InMemoryDecompressed,
ResolveBases,
ResolveDeltas,
ResolveBasesAndDeltas,
Expand All @@ -64,7 +63,6 @@ impl FromStr for MemoryMode {
let slc = s.to_ascii_lowercase();
Ok(match slc.as_str() {
"in-memory" => InMemory,
"in-memory-decompressed" => InMemoryDecompressed,
"resolve-bases" => ResolveBases,
"resolve-deltas" => ResolveDeltas,
"resolve-bases-and-deltas" => ResolveBasesAndDeltas,
Expand All @@ -78,7 +76,6 @@ impl From<MemoryMode> for pack::index::write::Mode {
use pack::index::write::Mode::*;
match v {
MemoryMode::InMemory => InMemory,
MemoryMode::InMemoryDecompressed => InMemoryDecompressed,
MemoryMode::ResolveBases => ResolveBases,
MemoryMode::ResolveDeltas => ResolveDeltas,
MemoryMode::ResolveBasesAndDeltas => ResolveBasesAndDeltas,
Expand Down
4 changes: 1 addition & 3 deletions src/plumbing/lean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ mod options {
///
/// Valid values are
/// - in-memory
/// * keep all objects in memory, compressed
/// - in-memory-decompressed
/// * as above, but decompressed, uses about twice as much memory, but does no unnecessary work
/// * keep all objects in memory, decompressed, avoiding decompression entirely.
/// - resolve-bases
/// * keep compressed deltas in memory, store the pack on disk and resolve bases from there
/// - resolve-deltas
Expand Down

0 comments on commit 1e2ec7e

Please sign in to comment.