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

repo: leverage stored index to calculate shortest prefix in commit id space

With my "jj" work repo, this saves ~4ms to show the log with default revset.

Command:
    JJ_CONFIG=/dev/null hyperfine --warmup 3 --runs 100 \
      "jj log -T 'commit_id.short_prefix_and_brackets() \
                  change_id.short_prefix_and_brackets()' \
              --no-commit-working-copy"

Baseline (a7541e1ba4):
    Time (mean ± σ):      54.1 ms ±  16.4 ms    [User: 46.4 ms, System: 7.8 ms]
    Range (min … max):    36.5 ms …  78.1 ms    100 runs

This commit:
    Time (mean ± σ):      49.5 ms ±  16.4 ms    [User: 42.4 ms, System: 7.2 ms]
    Range (min … max):    31.4 ms …  70.9 ms    100 runs
This commit is contained in:
Yuya Nishihara 2023-01-20 16:42:04 +09:00
parent 2e9468772b
commit 879f585b21

View file

@ -102,7 +102,6 @@ pub struct ReadonlyRepo {
index_store: Arc<IndexStore>,
index: OnceCell<Arc<ReadonlyIndex>>,
// TODO: This should eventually become part of the index and not be stored fully in memory.
commit_id_index: OnceCell<IdIndex>,
change_id_index: OnceCell<IdIndex>,
view: View,
}
@ -193,7 +192,6 @@ impl ReadonlyRepo {
settings: repo_settings,
index_store,
index: OnceCell::new(),
commit_id_index: OnceCell::new(),
change_id_index: OnceCell::new(),
view,
}))
@ -245,17 +243,6 @@ impl ReadonlyRepo {
})
}
fn commit_id_index(&self) -> &IdIndex {
self.commit_id_index.get_or_init(|| {
// We need to account for rewritten commits as well
let mut id_index = IdIndex::new();
for entry in self.as_repo_ref().index().iter() {
id_index.insert(entry.commit_id().as_bytes(), ());
}
id_index
})
}
fn change_id_index(&self) -> &IdIndex {
self.change_id_index.get_or_init(|| {
let all_visible_revisions = crate::revset::RevsetExpression::all()
@ -278,8 +265,8 @@ impl ReadonlyRepo {
// The root change/commit ids share the same prefix, and they are found in both
// indices with different lengths. So we have to feed bytes of valid lengths.
cmp::max(
self.commit_id_index()
.shortest_unique_prefix_len(root_commit_id.as_bytes()),
self.index()
.shortest_unique_commit_id_prefix_len(root_commit_id),
self.change_id_index()
.shortest_unique_prefix_len(root_change_id.as_bytes()),
)
@ -289,8 +276,8 @@ impl ReadonlyRepo {
// `max(len, anything_else)`, so a max of such lengths will disambiguate in all
// indices.
cmp::max(
self.commit_id_index()
.shortest_unique_prefix_len(target_id_bytes),
self.index()
.shortest_unique_commit_id_prefix_len(&CommitId::from_bytes(target_id_bytes)),
self.change_id_index()
.shortest_unique_prefix_len(target_id_bytes),
)
@ -551,7 +538,6 @@ impl RepoLoader {
settings: self.repo_settings.clone(),
index_store: self.index_store.clone(),
index: OnceCell::with_value(index),
commit_id_index: OnceCell::new(),
change_id_index: OnceCell::new(),
view,
};
@ -583,7 +569,6 @@ impl RepoLoader {
settings: self.repo_settings.clone(),
index_store: self.index_store.clone(),
index: OnceCell::new(),
commit_id_index: OnceCell::new(),
change_id_index: OnceCell::new(),
view,
};