Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 9bd8a7ba authored by TROPHIME Valentin's avatar TROPHIME Valentin
Browse files

fix(reactivity): change block size finer grain

parent d3a89863
No related branches found
No related tags found
No related merge requests found
......@@ -26,6 +26,7 @@ impl<T, I: Iterator<Item = T>> PreemptiveIterator for I {
let react_us = reactivity.as_micros();
loop {
let start = Instant::now();
let mut total_block = 0;
let mut time = Duration::from_micros(0);
while time < reactivity {
acc = self.by_ref().take(n_iters - 1).fold(acc, &mut f);
......@@ -38,12 +39,13 @@ impl<T, I: Iterator<Item = T>> PreemptiveIterator for I {
return acc;
}
time = start.elapsed();
total_block += n_iters;
n_iters *= 2;
}
let time_us = time.as_micros();
// forced to pass by percent value to avoid floats for adjusting iteration
let percent = ((100 * (time_us - react_us)) / react_us) as usize;
n_iters = n_iters.saturating_sub(((n_iters - 1) * percent) / 100);
n_iters = total_block.saturating_sub(((total_block - 1) * percent) / 100);
yield_now().await;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment