rotate the participants in the cycle once

Rotate the participants in the cycle when the cycle is created
rather than doing it "on the fly" each time they are iterated.
This commit is contained in:
Niko Matsakis 2021-11-02 05:57:01 -04:00
parent 1011274c9c
commit 7dbacbcf2b
2 changed files with 13 additions and 6 deletions

View file

@ -667,12 +667,7 @@ impl Cycle {
/// is arbitrary but deterministic, but the ordering is otherwise determined
/// by the execution.
pub fn participant_keys(&self) -> impl Iterator<Item = DatabaseKeyIndex> + '_ {
let min = self.participants.iter().min().unwrap();
let index = self.participants.iter().position(|p| p == min).unwrap();
self.participants[index..]
.iter()
.chain(self.participants[..index].iter())
.copied()
self.participants.iter().copied()
}
/// Returns a vector with the debug information for

View file

@ -286,6 +286,18 @@ impl Runtime {
to_id,
|aq| v.push(aq.database_key_index),
);
// We want to give the participants in a deterministic order
// (at least for this execution, not necessarily across executions),
// no matter where it started on the stack. Find the minimum
// key and rotate it to the front.
let min = v.iter().min().unwrap();
let index = v.iter().position(|p| p == min).unwrap();
v.rotate_left(index);
// No need to store extra memory.
v.shrink_to_fit();
Cycle::new(Arc::new(v))
};
debug!("cycle {:?}", cycle.debug(db));