Skip to content

Commit

Permalink
make commit lookup in log faster
Browse files Browse the repository at this point in the history
* makes hopping to next highlighted commit loopfree (closes extrawurst#1876)
* makes general commit find faster
  • Loading branch information
extrawurst authored and IndianBoy42 committed Jun 4, 2024
1 parent 7881a42 commit 7314a65
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 36 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Fixes
* log: major lag when going beyond last search hit ([#1876](https://github.com/extrawurst/gitui/issues/1876))

### Changed
* parallelise log search - performance gain ~100% ([#1869](https://github.com/extrawurst/gitui/issues/1869))
* search message body/summary separately ([#1875](https://github.com/extrawurst/gitui/issues/1875))


## [0.24.2] - 2023-09-03

### Fixes
Expand Down
75 changes: 41 additions & 34 deletions src/components/commitlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct CommitList {
highlighted_selection: Option<usize>,
items: ItemBatch,
highlights: Option<Rc<IndexSet<CommitId>>>,
commits: Vec<CommitId>,
commits: IndexSet<CommitId>,
marked: Vec<(usize, CommitId)>,
scroll_state: (Instant, f32),
tags: Option<Tags>,
Expand Down Expand Up @@ -72,7 +72,7 @@ impl CommitList {
marked: Vec::with_capacity(2),
selection: 0,
highlighted_selection: None,
commits: Vec::new(),
commits: IndexSet::new(),
highlights: None,
scroll_state: (Instant::now(), 0_f32),
tags: None,
Expand Down Expand Up @@ -100,7 +100,7 @@ impl CommitList {

///
pub fn copy_items(&self) -> Vec<CommitId> {
self.commits.clone()
self.commits.iter().copied().collect_vec()
}

///
Expand Down Expand Up @@ -224,7 +224,7 @@ impl CommitList {
}

///
pub fn set_commits(&mut self, commits: Vec<CommitId>) {
pub fn set_commits(&mut self, commits: IndexSet<CommitId>) {
if commits != self.commits {
self.items.clear();
self.commits = commits;
Expand Down Expand Up @@ -268,10 +268,10 @@ impl CommitList {

///
pub fn select_commit(&mut self, id: CommitId) -> Result<()> {
let position = self.commits.iter().position(|&x| x == id);
let index = self.commits.get_index_of(&id);

if let Some(position) = position {
self.selection = position;
if let Some(index) = index {
self.selection = index;
self.set_highlighted_selection_index();
Ok(())
} else {
Expand Down Expand Up @@ -332,35 +332,39 @@ impl CommitList {
&mut self,
scroll: ScrollType,
) -> Result<bool> {
let old_selection = self.selection;
let (current_index, selection_max) =
self.highlighted_selection_info();

loop {
let new_selection = match scroll {
ScrollType::Up => self.selection.saturating_sub(1),
ScrollType::Down => self.selection.saturating_add(1),

//TODO: support this?
// ScrollType::Home => 0,
// ScrollType::End => self.selection_max(),
_ => return Ok(false),
};
let new_index = match scroll {
ScrollType::Up => current_index.saturating_sub(1),
ScrollType::Down => current_index.saturating_add(1),

let new_selection =
cmp::min(new_selection, self.selection_max());
let selection_changed = new_selection != self.selection;
//TODO: support this?
// ScrollType::Home => 0,
// ScrollType::End => self.selection_max(),
_ => return Ok(false),
};

if !selection_changed {
self.selection = old_selection;
return Ok(false);
}
let new_index =
cmp::min(new_index, selection_max.saturating_sub(1));

self.selection = new_selection;
let index_changed = new_index != current_index;

if self.selection_highlighted() {
self.set_highlighted_selection_index();
return Ok(true);
}
if !index_changed {
return Ok(false);
}

let new_selected_commit =
self.highlights.as_ref().and_then(|highlights| {
highlights.iter().nth(new_index).copied()
});

if let Some(c) = new_selected_commit {
self.select_commit(c)?;
return Ok(true);
}

Ok(false)
}

fn move_selection_normal(
Expand Down Expand Up @@ -754,12 +758,15 @@ impl CommitList {
.unwrap_or_default();

if !index_in_sync || !self.is_list_in_sync() || force {
let slice_end =
want_min.saturating_add(SLICE_SIZE).min(commits);

let commits = sync::get_commits_info(
&self.repo.borrow(),
&self.commits[want_min..slice_end],
self.commits
.iter()
.skip(want_min)
.take(SLICE_SIZE)
.copied()
.collect_vec()
.as_slice(),
self.current_size()
.map_or(100u16, |size| size.0)
.into(),
Expand Down
2 changes: 1 addition & 1 deletion src/tabs/stashlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl StashList {
pub fn update(&mut self) -> Result<()> {
if self.is_visible() {
let stashes = sync::get_stashes(&self.repo.borrow())?;
self.list.set_commits(stashes);
self.list.set_commits(stashes.into_iter().collect());
}

Ok(())
Expand Down

0 comments on commit 7314a65

Please sign in to comment.