ok/jj
1
0
Fork 0
forked from mirrors/jj

index: use loaded readonly data without splitting into vecs

Since lookup data isn't typically small, .split_off() can take a few
milliseconds to memcpy().
This commit is contained in:
Yuya Nishihara 2023-12-13 19:20:44 +09:00
parent 5121e1f4e9
commit 95a0cceb97

View file

@ -132,9 +132,7 @@ pub(super) struct ReadonlyIndexSegment {
commit_lookup_entry_size: usize, commit_lookup_entry_size: usize,
// Number of commits not counting the parent file // Number of commits not counting the parent file
num_local_commits: u32, num_local_commits: u32,
graph: Vec<u8>, data: Vec<u8>,
lookup: Vec<u8>,
overflow_parent: Vec<u8>,
} }
impl Debug for ReadonlyIndexSegment { impl Debug for ReadonlyIndexSegment {
@ -189,9 +187,6 @@ impl ReadonlyIndexSegment {
if data.len() != expected_size { if data.len() != expected_size {
return Err(IndexLoadError::IndexCorrupt(name)); return Err(IndexLoadError::IndexCorrupt(name));
} }
let overflow_parent = data.split_off(graph_size + lookup_size);
let lookup = data.split_off(graph_size);
let graph = data;
Ok(Arc::new(ReadonlyIndexSegment { Ok(Arc::new(ReadonlyIndexSegment {
parent_file: maybe_parent_file, parent_file: maybe_parent_file,
num_parent_commits, num_parent_commits,
@ -201,9 +196,7 @@ impl ReadonlyIndexSegment {
commit_graph_entry_size, commit_graph_entry_size,
commit_lookup_entry_size, commit_lookup_entry_size,
num_local_commits: num_commits, num_local_commits: num_commits,
graph, data,
lookup,
overflow_parent,
})) }))
} }
@ -224,26 +217,31 @@ impl ReadonlyIndexSegment {
} }
fn graph_entry(&self, local_pos: u32) -> CommitGraphEntry { fn graph_entry(&self, local_pos: u32) -> CommitGraphEntry {
assert!(local_pos < self.num_local_commits);
let offset = (local_pos as usize) * self.commit_graph_entry_size; let offset = (local_pos as usize) * self.commit_graph_entry_size;
CommitGraphEntry { CommitGraphEntry {
data: &self.graph[offset..][..self.commit_graph_entry_size], data: &self.data[offset..][..self.commit_graph_entry_size],
commit_id_length: self.commit_id_length, commit_id_length: self.commit_id_length,
change_id_length: self.change_id_length, change_id_length: self.change_id_length,
} }
} }
fn lookup_entry(&self, lookup_pos: u32) -> CommitLookupEntry { fn lookup_entry(&self, lookup_pos: u32) -> CommitLookupEntry {
let offset = (lookup_pos as usize) * self.commit_lookup_entry_size; assert!(lookup_pos < self.num_local_commits);
let offset = (lookup_pos as usize) * self.commit_lookup_entry_size
+ (self.num_local_commits as usize) * self.commit_graph_entry_size;
CommitLookupEntry { CommitLookupEntry {
data: &self.lookup[offset..][..self.commit_lookup_entry_size], data: &self.data[offset..][..self.commit_lookup_entry_size],
commit_id_length: self.commit_id_length, commit_id_length: self.commit_id_length,
} }
} }
fn overflow_parent(&self, overflow_pos: u32) -> IndexPosition { fn overflow_parent(&self, overflow_pos: u32) -> IndexPosition {
let offset = (overflow_pos as usize) * 4; let offset = (overflow_pos as usize) * 4
+ (self.num_local_commits as usize) * self.commit_graph_entry_size
+ (self.num_local_commits as usize) * self.commit_lookup_entry_size;
IndexPosition( IndexPosition(
(&self.overflow_parent[offset..][..4]) (&self.data[offset..][..4])
.read_u32::<LittleEndian>() .read_u32::<LittleEndian>()
.unwrap(), .unwrap(),
) )