Skip to content

Commit

Permalink
[pack #167] Use custom uluru version to avoid a lot of allocations…
Browse files Browse the repository at this point in the history
…even though that doesn't really translate into much performance,
despite technically saving millions of allocations. Maybe allocators
are already pretty good at this.
  • Loading branch information
Byron committed Aug 22, 2021
1 parent 65e29de commit 8d49976
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion git-pack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ itoa = "0.4.6"
bytesize = "1.0.1"
parking_lot = { version = "0.11.0", default-features = false }
thiserror = "1.0.26"
uluru = { version = "2.2.0", optional = true }
uluru = { version = "2.2.0", optional = true, git = "https://github.com/Byron/uluru", features = ["std"], branch = "master"}
memory-lru = { version = "0.1.0", optional = true }
dashmap = "4.0.2"

Expand Down
19 changes: 15 additions & 4 deletions git-pack/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,28 @@ pub mod lru {
/// The cache must be small as the search is 'naive' and the underlying data structure is a linked list.
/// Values of 64 seem to improve performance.
#[derive(Default)]
pub struct StaticLinkedList<const SIZE: usize>(uluru::LRUCache<Entry, SIZE>);
pub struct StaticLinkedList<const SIZE: usize>(uluru::LRUCache<Entry, SIZE>, Vec<Vec<u8>>);

impl<const SIZE: usize> DecodeEntry for StaticLinkedList<SIZE> {
fn put(&mut self, pack_id: u32, offset: u64, data: &[u8], kind: git_object::Kind, compressed_size: usize) {
self.0.insert(Entry {
if let Some(previous) = self.0.insert(Entry {
offset,
pack_id,
data: Vec::from(data),
data: self
.1
.pop()
.map(|mut v| {
v.clear();
v.resize(data.len(), 0);
v.copy_from_slice(data);
v
})
.unwrap_or_else(|| Vec::from(data)),
kind,
compressed_size,
})
}) {
self.1.push(previous.data)
}
}

fn get(&mut self, pack_id: u32, offset: u64, out: &mut Vec<u8>) -> Option<(git_object::Kind, usize)> {
Expand Down

0 comments on commit 8d49976

Please sign in to comment.