Skip to content

Commit

Permalink
unrelated technical debt: make sure to run par_iter within the contex…
Browse files Browse the repository at this point in the history
…t of an existing thread pool (avoid creating a global thread pool if possible)
  • Loading branch information
michaelsutton committed Nov 28, 2024
1 parent bc15537 commit 59d2690
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 4 additions & 3 deletions consensus/src/consensus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,12 +767,13 @@ impl ConsensusApi for Consensus {
let mut pruning_utxoset_write = self.pruning_utxoset_stores.write();
pruning_utxoset_write.utxo_set.write_many(utxoset_chunk).unwrap();

// Parallelize processing
let inner_multiset =
// Parallelize processing using the context of an existing thread pool.
let inner_multiset = self.virtual_processor.install(|| {
utxoset_chunk.par_iter().map(|(outpoint, entry)| MuHash::from_utxo(outpoint, entry)).reduce(MuHash::new, |mut a, b| {
a.combine(&b);
a
});
})
});

current_multiset.combine(&inner_multiset);
}
Expand Down
9 changes: 9 additions & 0 deletions consensus/src/pipeline/virtual_processor/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,15 @@ impl VirtualStateProcessor {
true
}
}

/// Executes `op` within the thread pool associated with this processor.
pub fn install<OP, R>(&self, op: OP) -> R
where
OP: FnOnce() -> R + Send,
R: Send,
{
self.thread_pool.install(op)
}
}

enum MergesetIncreaseResult {
Expand Down

0 comments on commit 59d2690

Please sign in to comment.