phase 7.3: parallel @each using rayon (feature gate, threshold >= 10 items)
This commit is contained in:
@@ -427,13 +427,44 @@ impl Interpreter {
|
|||||||
|
|
||||||
let child_refs: Vec<&Element<'a>> = el.children.iter().collect();
|
let child_refs: Vec<&Element<'a>> = el.children.iter().collect();
|
||||||
|
|
||||||
|
#[cfg(feature = "parallel")]
|
||||||
|
if items.len() >= 10 {
|
||||||
|
use rayon::prelude::*;
|
||||||
|
let var_name_owned = var_name.to_string();
|
||||||
|
let vars_snapshot = variables.clone();
|
||||||
|
let results: Vec<Vec<Element<'a>>> = items
|
||||||
|
.par_iter()
|
||||||
|
.map(|item| {
|
||||||
|
let mut local_vars = vars_snapshot.clone();
|
||||||
|
local_vars.insert(var_name_owned.clone(), Value::Str(CompactString::new(item)));
|
||||||
|
Self::evaluate_vdom_incr(
|
||||||
|
&child_refs, &mut local_vars, components, rhei, stylesheet, ancestors, dirty_set,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
for result in results {
|
||||||
|
output.extend(result);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
for item in items {
|
for item in items {
|
||||||
let old_val = variables.insert(var_name.to_string(), Value::Str(CompactString::new(item)));
|
let old_val = variables.insert(var_name.to_string(), Value::Str(CompactString::new(item)));
|
||||||
|
|
||||||
output.extend(Self::evaluate_vdom_incr(
|
output.extend(Self::evaluate_vdom_incr(
|
||||||
&child_refs, variables, components, rhei, stylesheet, ancestors, dirty_set,
|
&child_refs, variables, components, rhei, stylesheet, ancestors, dirty_set,
|
||||||
));
|
));
|
||||||
|
if let Some(old) = old_val {
|
||||||
|
variables.insert(var_name.to_string(), old);
|
||||||
|
} else {
|
||||||
|
variables.remove(var_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "parallel"))]
|
||||||
|
for item in items {
|
||||||
|
let old_val = variables.insert(var_name.to_string(), Value::Str(CompactString::new(item)));
|
||||||
|
output.extend(Self::evaluate_vdom_incr(
|
||||||
|
&child_refs, variables, components, rhei, stylesheet, ancestors, dirty_set,
|
||||||
|
));
|
||||||
if let Some(old) = old_val {
|
if let Some(old) = old_val {
|
||||||
variables.insert(var_name.to_string(), old);
|
variables.insert(var_name.to_string(), old);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user