History

unify trait bounds for parallel code: prefer Clone over Sync (#259)

Sebastian Thiel committed 4 years ago

Commit c805d0b1 parent 3c790e06 files · +24 −24Browse files

Unified · Split

6 files
  1. DEVELOPMENT.md +6 −0
  2. git-features/src/parallel/in_parallel.rs +4 −4
  3. git-features/src/parallel/mod.rs +2 −2
  4. git-features/src/parallel/reduce.rs +7 −13
  5. git-pack/src/data/output/count/objects/mod.rs +2 −2
  6. git-pack/src/data/output/entry/iter_from_counts.rs +3 −3
DEVELOPMENT.md+6−0
@@ -683,3 +683,9 @@ Please note that these are based on the following value system: · 682 unmodified lines
683683 a single-threaded version).
684684 - Maybe… after some benchmarks, we can entirely drop the single-threaded version if it's not significantly faster on a single thread (without thread primiives) than the
685685 same with multi-threading (but a single-thread).
686+ - Servers would be split into readers and writers, where…
687+ - …readers share a common pool and thus all maps, with lazy loading and refresh (but their pack-ids change due to that, and packs might disappear)
688+ - …writers when…
689+ - …cloning use an eagerly loaded Repository just for that particular clone for stable pack ids
690+ - …fetches use a lazy-loaded Repository with refresh disabled, and full retries if the pack they were referring to goes away. Maybe there can be a policy for that to keep
691+ pack ids stable despite refresh, which would also solve clones which could then lazy-load.
git-features/src/parallel/in_parallel.rs+4−4
@@ -22,8 +22,8 @@ pub fn join<O1: Send, O2: Send>(left: impl FnOnce() -> O1 + Send, right: impl Fn · 21 unmodified lines
2222 pub fn in_parallel<I, S, O, R>(
2323 input: impl Iterator<Item = I> + Send,
2424 thread_limit: Option<usize>,
25− new_thread_state: impl Fn(usize) -> S + Send + Sync,
26− consume: impl Fn(I, &mut S) -> O + Send + Sync,
25+ new_thread_state: impl Fn(usize) -> S + Send + Clone,
26+ consume: impl Fn(I, &mut S) -> O + Send + Clone,
2727 mut reducer: R,
2828 ) -> Result<<R as Reduce>::Output, <R as Reduce>::Error>
2929 where
@@ -32,8 +32,6 @@ where · 2 unmodified lines
3232 O: Send,
3333 {
3434 let num_threads = num_threads(thread_limit);
35− let new_thread_state = &new_thread_state;
36− let consume = &consume;
3735 crossbeam_utils::thread::scope(move |s| {
3836 let receive_result = {
3937 let (send_input, receive_input) = crossbeam_channel::bounded::<I>(num_threads);
@@ -42,6 +40,8 @@ where · 2 unmodified lines
4240 s.spawn({
4341 let send_result = send_result.clone();
4442 let receive_input = receive_input.clone();
43+ let new_thread_state = new_thread_state.clone();
44+ let consume = consume.clone();
4545 move |_| {
4646 let mut state = new_thread_state(thread_id);
4747 for item in receive_input {
git-features/src/parallel/mod.rs+2−2
@@ -133,8 +133,8 @@ pub fn in_parallel_if<I, S, O, R>( · 132 unmodified lines
133133 condition: impl FnOnce() -> bool,
134134 input: impl Iterator<Item = I> + Send,
135135 thread_limit: Option<usize>,
136− new_thread_state: impl Fn(usize) -> S + Send + Sync,
137− consume: impl Fn(I, &mut S) -> O + Send + Sync,
136+ new_thread_state: impl Fn(usize) -> S + Send + Clone,
137+ consume: impl Fn(I, &mut S) -> O + Send + Clone,
138138 reducer: R,
139139 ) -> Result<<R as Reduce>::Output, <R as Reduce>::Error>
140140 where
git-features/src/parallel/reduce.rs+7−13
@@ -138,11 +138,9 @@ mod stepped { · 137 unmodified lines
138138
139139 impl<InputIter, ConsumeFn, Reduce, I, O, S> Stepwise<InputIter, ConsumeFn, S, Reduce>
140140 where
141− InputIter: Iterator<Item = I> + Send,
142− ConsumeFn: Fn(I, &mut S) -> O + Send + Sync,
141+ InputIter: Iterator<Item = I>,
142+ ConsumeFn: Fn(I, &mut S) -> O,
143143 Reduce: super::Reduce<Input = O>,
144− I: Send,
145− O: Send,
146144 {
147145 /// Instantiate a new iterator.
148146 /// For a description of parameters, see [`in_parallel()`][crate::parallel::in_parallel()].
@@ -154,7 +152,7 @@ mod stepped { · 5 unmodified lines
154152 reducer: Reduce,
155153 ) -> Self
156154 where
157− ThreadStateFn: Fn(usize) -> S + Send + Sync,
155+ ThreadStateFn: Fn(usize) -> S,
158156 {
159157 Stepwise {
160158 input,
@@ -175,11 +173,9 @@ mod stepped { · 14 unmodified lines
175173
176174 impl<InputIter, ConsumeFn, ThreadState, Reduce, I, O> Iterator for Stepwise<InputIter, ConsumeFn, ThreadState, Reduce>
177175 where
178− InputIter: Iterator<Item = I> + Send,
179− ConsumeFn: Fn(I, &mut ThreadState) -> O + Send + Sync,
176+ InputIter: Iterator<Item = I>,
177+ ConsumeFn: Fn(I, &mut ThreadState) -> O,
180178 Reduce: super::Reduce<Input = O>,
181− I: Send,
182− O: Send,
183179 {
184180 type Item = Result<Reduce::FeedProduce, Reduce::Error>;
185181
@@ -192,11 +188,9 @@ mod stepped { · 6 unmodified lines
192188
193189 impl<InputIter, ConsumeFn, R, I, O, S> super::Finalize for Stepwise<InputIter, ConsumeFn, S, R>
194190 where
195− InputIter: Iterator<Item = I> + Send,
196− ConsumeFn: Fn(I, &mut S) -> O + Send + Sync,
191+ InputIter: Iterator<Item = I>,
192+ ConsumeFn: Fn(I, &mut S) -> O,
197193 R: super::Reduce<Input = O>,
198− I: Send,
199− O: Send,
200194 {
201195 type Reduce = R;
202196
git-pack/src/data/output/count/objects/mod.rs+2−2
@@ -39,7 +39,7 @@ pub type Result<E1, E2> = std::result::Result<(Vec<output::Count>, Outcome), Err · 38 unmodified lines
3939 /// * more configuration
4040 pub fn objects<Find, Iter, IterErr, Oid, PackCache, ObjectCache>(
4141 db: Find,
42− make_caches: impl Fn() -> (PackCache, ObjectCache) + Send + Sync,
42+ make_caches: impl Fn() -> (PackCache, ObjectCache) + Send + Clone,
4343 objects_ids: Iter,
4444 progress: impl Progress,
4545 should_interrupt: &AtomicBool,
@@ -50,7 +50,7 @@ pub fn objects<Find, Iter, IterErr, Oid, PackCache, ObjectCache>( · 4 unmodified lines
5050 }: Options,
5151 ) -> Result<find::existing::Error<Find::Error>, IterErr>
5252 where
53− Find: crate::Find + Send + Sync,
53+ Find: crate::Find + Send + Clone,
5454 <Find as crate::Find>::Error: Send,
5555 Iter: Iterator<Item = std::result::Result<Oid, IterErr>> + Send,
5656 Oid: Into<ObjectId> + Send,
git-pack/src/data/output/entry/iter_from_counts.rs+3−3
@@ -42,7 +42,7 @@ use crate::data::{output, output::ChunkId}; · 41 unmodified lines
4242 pub fn iter_from_counts<Find, Cache>(
4343 mut counts: Vec<output::Count>,
4444 db: Find,
45− make_cache: impl Fn() -> Cache + Send + Sync + 'static,
45+ make_cache: impl Fn() -> Cache + Send + Clone + Sync + 'static,
4646 mut progress: impl Progress,
4747 Options {
4848 version,
@@ -54,7 +54,7 @@ pub fn iter_from_counts<Find, Cache>( · 5 unmodified lines
5454 ) -> impl Iterator<Item = Result<(ChunkId, Vec<output::Entry>), Error<Find::Error>>>
5555 + parallel::reduce::Finalize<Reduce = reduce::Statistics<Error<Find::Error>>>
5656 where
57− Find: crate::Find + Send + Sync + 'static,
57+ Find: crate::Find + Send + Clone + 'static,
5858 <Find as crate::Find>::Error: Send,
5959 Cache: crate::cache::DecodeEntry,
6060 {
@@ -78,7 +78,7 @@ where · 17 unmodified lines
7878 {
7979 let progress = Arc::clone(&progress);
8080 let counts = &counts;
81− let db = &db;
81+ let db = db.clone();
8282 move |chunk_range, buf| {
8383 let chunk = {
8484 let c = &counts[chunk_range];

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t