From b352e15b9ee735f5282678ca5f0a7e800d5694b4 Mon Sep 17 00:00:00 2001 From: Georg Wiese Date: Thu, 9 Jan 2025 04:53:04 +0100 Subject: [PATCH] Parallelize index lookup => 30% faster --- executor/src/witgen/multiplicity_column_generator.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/executor/src/witgen/multiplicity_column_generator.rs b/executor/src/witgen/multiplicity_column_generator.rs index 1d8149ff5..d7e8a6f91 100644 --- a/executor/src/witgen/multiplicity_column_generator.rs +++ b/executor/src/witgen/multiplicity_column_generator.rs @@ -123,8 +123,14 @@ impl<'a, T: FieldElement> MultiplicityColumnGenerator<'a, T> { .or_insert_with(|| vec![0; rhs_machine_size]); assert_eq!(multiplicities.len(), rhs_machine_size); - for (_, tuple) in lhs_tuples { - multiplicities[index[&tuple]] += 1; + // Looking up the index is slow, so we do it in parallel. + let indices = lhs_tuples + .into_par_iter() + .map(|(_, tuple)| index[&tuple]) + .collect::>(); + + for index in indices { + multiplicities[index] += 1; } log::trace!( " Done updating multiplicities, took: {}s",