Skip to content

Commit

Permalink
turns out you never want to keep deltas in memory
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Aug 4, 2020
1 parent 1e2ec7e commit 657aa2c
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 18 deletions.
2 changes: 1 addition & 1 deletion git-odb/src/pack/index/write/consume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ where
let mut bytes_buf = bytes_buf.borrow_mut();
bytes_buf.resize(entry_size, 0);
match mode {
Mode::ResolveDeltas | Mode::ResolveBases | Mode::ResolveBasesAndDeltas => {
Mode::ResolveDeltas | Mode::ResolveBasesAndDeltas => {
resolve(pack_offset..pack_offset + entry_size as u64, &mut bytes_buf)
.ok_or_else(|| Error::ConsumeResolveFailed(pack_offset))?;
let entry = pack::data::Entry::from_bytes(&bytes_buf, pack_offset);
Expand Down
8 changes: 3 additions & 5 deletions git-odb/src/pack/index/write/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ pub type EntrySlice = std::ops::Range<u64>;
pub enum Mode {
/// Base + deltas in memory, decompressed
InMemory,
/// Deltas in memory, decompressed
ResolveBases,
/// Bases in memory, decompressed
ResolveDeltas,
ResolveBasesAndDeltas,
Expand All @@ -78,19 +76,19 @@ impl Mode {
pub(crate) fn base_cache(&self, decompressed: Vec<u8>) -> Cache {
match self {
Mode::InMemory | Mode::ResolveDeltas => Cache::Decompressed(decompressed),
Mode::ResolveBases | Mode::ResolveBasesAndDeltas => Cache::Unset,
Mode::ResolveBasesAndDeltas => Cache::Unset,
}
}
pub(crate) fn delta_cache(&self, decompressed: Vec<u8>) -> Cache {
match self {
Mode::ResolveBases | Mode::InMemory => Cache::Decompressed(decompressed),
Mode::InMemory => Cache::Decompressed(decompressed),
Mode::ResolveDeltas | Mode::ResolveBasesAndDeltas => Cache::Unset,
}
}
pub(crate) fn is_in_memory(&self) -> bool {
match self {
Mode::InMemory => true,
Mode::ResolveBases | Mode::ResolveDeltas | Mode::ResolveBasesAndDeltas => false,
Mode::ResolveDeltas | Mode::ResolveBasesAndDeltas => false,
}
}
}
Expand Down
7 changes: 1 addition & 6 deletions git-odb/tests/pack/tree.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#[test]
fn using_option_as_data_does_not_increase_size_in_memory() {
enum Cache {
_Unset,
_Decompressed(Vec<u8>),
}
enum ObjectKind {
_Base(git_object::Kind),
_OfsDelta,
Expand All @@ -14,7 +10,6 @@ fn using_option_as_data_does_not_increase_size_in_memory() {
pub _entry_len: usize,
pub _kind: ObjectKind,
pub _crc32: u32,
pub _cache: Cache,
}

struct TreeItem<D> {
Expand All @@ -34,7 +29,7 @@ fn using_option_as_data_does_not_increase_size_in_memory() {
);
assert_eq!(
std::mem::size_of::<[TreeItemOption<Entry>; 7_500_000]>(),
780000000,
600_000_000,
"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,
ResolveBases,
ResolveDeltas,
ResolveBasesAndDeltas,
}
Expand All @@ -63,7 +62,6 @@ impl FromStr for MemoryMode {
let slc = s.to_ascii_lowercase();
Ok(match slc.as_str() {
"in-memory" => InMemory,
"resolve-bases" => ResolveBases,
"resolve-deltas" => ResolveDeltas,
"resolve-bases-and-deltas" => ResolveBasesAndDeltas,
_ => return Err("invalid value".into()),
Expand All @@ -76,7 +74,6 @@ impl From<MemoryMode> for pack::index::write::Mode {
use pack::index::write::Mode::*;
match v {
MemoryMode::InMemory => InMemory,
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 @@ -55,10 +55,8 @@ mod options {
/// Valid values are
/// - in-memory
/// * 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
/// * as above, but keep compressed bases
/// * keep compressed bases in memory, store the pack on disk and resolve deltas from there
/// - resolve-bases-and-deltas
/// * as above, but resolve all objects, store none in memory
/// * this option duplicates most work, but uses the least memory
Expand Down

0 comments on commit 657aa2c

Please sign in to comment.