Skip to content

Commit 52dfefe

Browse files
committed
Revert "parallelize log search"
This reverts commit ebe41e8.
1 parent ebe41e8 commit 52dfefe

File tree

6 files changed

+37
-89
lines changed

6 files changed

+37
-89
lines changed

CHANGELOG.md

-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
* fix commit log not updating after branch switch ([#1862](https://github.com/extrawurst/gitui/issues/1862))
1212
* fix stashlist not updating after pop/drop ([#1864](https://github.com/extrawurst/gitui/issues/1864))
1313

14-
### Changed
15-
* log search consumes all cores now and got even faster
16-
1714
## [0.24.1] - 2023-08-30
1815

1916
### Fixes

Cargo.lock

-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
.PHONY: debug build-release release-linux-musl test clippy clippy-pedantic install install-debug
33

44
ARGS=-l
5-
# ARGS=-l -d ~/code/extern/kubernetes
65
# ARGS=-l -d ~/code/extern/linux
76
# ARGS=-l -d ~/code/git-bare-test.git -w ~/code/git-bare-test
87

asyncgit/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ log = "0.4"
2222
# git2 = { git="https://github.com/extrawurst/git2-rs.git", rev="fc13dcc", features = ["vendored-openssl"]}
2323
# pinning to vendored openssl, using the git2 feature this gets lost with new resolver
2424
openssl-sys = { version = '0.9', features = ["vendored"], optional = true }
25-
rayon = "1.7"
2625
rayon-core = "1.11"
2726
scopetime = { path = "../scopetime", version = "0.1" }
2827
serde = { version = "1.0", features = ["derive"] }

asyncgit/src/asyncjob/mod.rs

+6-15
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,12 @@ use crossbeam_channel::Sender;
77
use std::sync::{Arc, Mutex, RwLock};
88

99
/// Passed to `AsyncJob::run` allowing sending intermediate progress notifications
10-
pub struct RunParams<
11-
T: Copy + Send,
12-
P: Clone + Send + Sync + PartialEq,
13-
> {
10+
pub struct RunParams<T: Copy + Send, P: Clone + Send + Sync> {
1411
sender: Sender<T>,
1512
progress: Arc<RwLock<P>>,
1613
}
1714

18-
impl<T: Copy + Send, P: Clone + Send + Sync + PartialEq>
19-
RunParams<T, P>
20-
{
15+
impl<T: Copy + Send, P: Clone + Send + Sync> RunParams<T, P> {
2116
/// send an intermediate update notification.
2217
/// do not confuse this with the return value of `run`.
2318
/// `send` should only be used about progress notifications
@@ -29,13 +24,9 @@ impl<T: Copy + Send, P: Clone + Send + Sync + PartialEq>
2924
}
3025

3126
/// set the current progress
32-
pub fn set_progress(&self, p: P) -> Result<bool> {
33-
Ok(if *self.progress.read()? == p {
34-
false
35-
} else {
36-
*(self.progress.write()?) = p;
37-
true
38-
})
27+
pub fn set_progress(&self, p: P) -> Result<()> {
28+
*(self.progress.write()?) = p;
29+
Ok(())
3930
}
4031
}
4132

@@ -44,7 +35,7 @@ pub trait AsyncJob: Send + Sync + Clone {
4435
/// defines what notification type is used to communicate outside
4536
type Notification: Copy + Send;
4637
/// type of progress
47-
type Progress: Clone + Default + Send + Sync + PartialEq;
38+
type Progress: Clone + Default + Send + Sync;
4839

4940
/// can run a synchronous time intensive task.
5041
/// the returned notification is used to tell interested parties

asyncgit/src/filter_commits.rs

+31-58
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
use rayon::{
2-
prelude::ParallelIterator,
3-
slice::{ParallelSlice, ParallelSliceMut},
4-
};
5-
61
use crate::{
72
asyncjob::{AsyncJob, RunParams},
83
error::Result,
94
sync::{self, CommitId, RepoPath, SharedCommitFilterFn},
105
AsyncGitNotification, ProgressPercent,
116
};
127
use std::{
13-
sync::{atomic::AtomicUsize, Arc, Mutex},
8+
sync::{Arc, Mutex},
149
time::{Duration, Instant},
1510
};
1611

@@ -74,62 +69,44 @@ impl AsyncCommitFilterJob {
7469
commits: Vec<CommitId>,
7570
params: &RunParams<AsyncGitNotification, ProgressPercent>,
7671
) -> JobState {
77-
let (start, result) =
78-
self.filter_commits(repo_path, commits, params);
79-
80-
//TODO: still need this to be a result?
81-
JobState::Response(Ok(CommitFilterResult {
82-
result,
83-
duration: start.elapsed(),
84-
}))
72+
let response = sync::repo(repo_path)
73+
.map(|repo| self.filter_commits(&repo, commits, params))
74+
.map(|(start, result)| CommitFilterResult {
75+
result,
76+
duration: start.elapsed(),
77+
});
78+
79+
JobState::Response(response)
8580
}
8681

8782
fn filter_commits(
8883
&self,
89-
repo_path: &RepoPath,
84+
repo: &git2::Repository,
9085
commits: Vec<CommitId>,
9186
params: &RunParams<AsyncGitNotification, ProgressPercent>,
9287
) -> (Instant, Vec<CommitId>) {
9388
let total_amount = commits.len();
9489
let start = Instant::now();
9590

96-
let idx = AtomicUsize::new(0);
97-
let mut result = commits
91+
let mut progress = ProgressPercent::new(0, total_amount);
92+
93+
let result = commits
9894
.into_iter()
9995
.enumerate()
100-
.collect::<Vec<(usize, CommitId)>>()
101-
.par_chunks(1000)
102-
.filter_map(|c| {
103-
//TODO: error log repo open errors
104-
sync::repo(repo_path).ok().map(|repo| {
105-
c.iter()
106-
.filter_map(|(e, c)| {
107-
let idx = idx.fetch_add(
108-
1,
109-
std::sync::atomic::Ordering::Relaxed,
110-
);
111-
112-
Self::update_progress(
113-
params,
114-
ProgressPercent::new(
115-
idx,
116-
total_amount,
117-
),
118-
);
119-
120-
(*self.filter)(&repo, c).ok().and_then(
121-
|res| res.then_some((*e, *c)),
122-
)
123-
})
124-
.collect::<Vec<_>>()
125-
})
126-
})
127-
.flatten()
128-
.collect::<Vec<_>>();
96+
.filter_map(|(idx, c)| {
97+
let new_progress =
98+
ProgressPercent::new(idx, total_amount);
12999

130-
result.par_sort_by(|a, b| a.0.cmp(&b.0));
100+
if new_progress != progress {
101+
Self::update_progress(params, new_progress);
102+
progress = new_progress;
103+
}
131104

132-
let result = result.into_iter().map(|c| c.1).collect();
105+
(*self.filter)(repo, &c)
106+
.ok()
107+
.and_then(|res| res.then_some(c))
108+
})
109+
.collect::<Vec<_>>();
133110

134111
(start, result)
135112
}
@@ -138,16 +115,12 @@ impl AsyncCommitFilterJob {
138115
params: &RunParams<AsyncGitNotification, ProgressPercent>,
139116
new_progress: ProgressPercent,
140117
) {
141-
match params.set_progress(new_progress) {
142-
Err(e) => log::error!("progress error: {e}"),
143-
Ok(result) if result => {
144-
if let Err(e) =
145-
params.send(AsyncGitNotification::CommitFilter)
146-
{
147-
log::error!("send error: {e}");
148-
}
149-
}
150-
_ => (),
118+
if let Err(e) = params.set_progress(new_progress) {
119+
log::error!("progress error: {e}");
120+
} else if let Err(e) =
121+
params.send(AsyncGitNotification::CommitFilter)
122+
{
123+
log::error!("send error: {e}");
151124
}
152125
}
153126
}

0 commit comments

Comments
 (0)