Skip to content

Commit 923692b

Browse files
committed
fix: memory capped hashmap as pack delta cache won't trash memory as much. (#851)
Previously it would take a buffer from the free-list, copy data into it, and when exceeding the capacity loose it entirely. Now the freelist is handled correctly.
1 parent 4f879bf commit 923692b

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

Diff for: gix-pack/src/cache/lru.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ mod memory {
4848
impl DecodeEntry for MemoryCappedHashmap {
4949
fn put(&mut self, pack_id: u32, offset: u64, data: &[u8], kind: gix_object::Kind, compressed_size: usize) {
5050
self.debug.put();
51-
if let Ok(Some(previous_entry)) = self.inner.put_with_weight(
51+
let res = self.inner.put_with_weight(
5252
(pack_id, offset),
5353
Entry {
5454
data: self
@@ -64,8 +64,11 @@ mod memory {
6464
kind,
6565
compressed_size,
6666
},
67-
) {
68-
self.free_list.push(previous_entry.data)
67+
);
68+
match res {
69+
Ok(Some(previous_entry)) => self.free_list.push(previous_entry.data),
70+
Ok(None) => {}
71+
Err((_key, value)) => self.free_list.push(value.data),
6972
}
7073
}
7174

Diff for: gix-pack/src/cache/object.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ mod memory {
5858
/// Put the object going by `id` of `kind` with `data` into the cache.
5959
fn put(&mut self, id: gix_hash::ObjectId, kind: gix_object::Kind, data: &[u8]) {
6060
self.debug.put();
61-
if let Ok(Some(previous_entry)) = self.inner.put_with_weight(
61+
let res = self.inner.put_with_weight(
6262
id,
6363
Entry {
6464
data: self
@@ -73,8 +73,11 @@ mod memory {
7373
.unwrap_or_else(|| Vec::from(data)),
7474
kind,
7575
},
76-
) {
77-
self.free_list.push(previous_entry.data)
76+
);
77+
match res {
78+
Ok(Some(previous_entry)) => self.free_list.push(previous_entry.data),
79+
Ok(None) => {}
80+
Err((_key, value)) => self.free_list.push(value.data),
7881
}
7982
}
8083

0 commit comments

Comments
 (0)