MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / run_maybe_parallel

Method run_maybe_parallel

crates/wasmtime/src/engine.rs:186–218  ·  view source on GitHub ↗
(
        &self,
        input: Vec<A>,
        f: F,
    )

Source from the content-addressed store, hash-verified

184 }
185
186 pub(crate) fn run_maybe_parallel<
187 A: Send,
188 B: Send,
189 E: Send,
190 F: Fn(A) -> Result<B, E> + Send + Sync,
191 >(
192 &self,
193 input: Vec<A>,
194 f: F,
195 ) -> Result<Vec<B>, E> {
196 if self.config().parallel_compilation {
197 #[cfg(feature = "parallel-compilation")]
198 {
199 use rayon::prelude::*;
200 // If we collect into Result<Vec<B>, E> directly, the returned error is not
201 // deterministic, because any error could be returned early. So we first materialize
202 // all results in order and then return the first error deterministically, or Ok(_).
203 return input
204 .into_par_iter()
205 .map(|a| f(a))
206 .collect::<Vec<Result<B, E>>>()
207 .into_iter()
208 .collect::<Result<Vec<B>, E>>();
209 }
210 }
211
212 // In case the parallel-compilation feature is disabled or the parallel_compilation config
213 // was turned off dynamically fallback to the non-parallel version.
214 input
215 .into_iter()
216 .map(|a| f(a))
217 .collect::<Result<Vec<B>, E>>()
218 }
219
220 #[cfg(any(feature = "cranelift", feature = "winch"))]
221 pub(crate) fn run_maybe_parallel_mut<

Callers 4

compileMethod · 0.80
compile_with_inliningMethod · 0.80
validateMethod · 0.80

Calls 5

into_par_iterMethod · 0.80
fFunction · 0.50
configMethod · 0.45
into_iterMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected