History

Chunk computation seems alright, what about realistic values

Sebastian Thiel committed 6 years ago

Commit 973e6bb1 parent a1b5d562 files · +5 −7Browse files

Unified · Split

2 files
  1. git-features/src/parallel.rs +4 −6
  2. git-features/tests/parallel.rs +1 −1
git-features/src/parallel.rs+4−6
@@ -134,16 +134,14 @@ pub fn optimize_chunk_size_and_thread_limit( · 133 unmodified lines
134134 let desired_chunks_per_thread_at_least = 2;
135135 let (chunk_size, thread_limit) = num_chunks
136136 .map(|num_chunks| {
137− let thread_limit = if num_chunks <= available_threads * desired_chunks_per_thread_at_least {
137+ let items = num_chunks * desired_chunk_size;
138+ let chunk_size = (items / (available_threads * desired_chunks_per_thread_at_least)).max(1);
139+ let num_chunks = items / chunk_size;
140+ let thread_limit = if num_chunks <= available_threads {
138141 (num_chunks / desired_chunks_per_thread_at_least).max(1)
139142 } else {
140143 available_threads
141144 };
142− let chunk_size = if num_chunks / thread_limit > desired_chunks_per_thread_at_least {
143− (desired_chunk_size * (num_chunks / thread_limit / desired_chunks_per_thread_at_least)).max(1)
144− } else {
145− desired_chunk_size
146− };
147145 (chunk_size, thread_limit)
148146 })
149147 .unwrap_or((desired_chunk_size, available_threads));
git-features/tests/parallel.rs+1−1
@@ -38,7 +38,7 @@ mod optimize_chunk_size_and_thread_limit { · 37 unmodified lines
3838 fn chunk_size_too_big() {
3939 assert_eq!(
4040 optimize_chunk_size_and_thread_limit(50, Some(2), None, Some(10)),
41− (2, Some(10))
41+ (5, Some(10))
4242 );
4343 }
4444 }