Skip to content

Commit

Permalink
perf(es/utils): Optimize maybe_par_idx_raw (#9870)
Browse files Browse the repository at this point in the history
**Description:**

I was not sure if two creates in parallel were faster than single create in the original thread at the moment of writing the function, but when I tried, single create was faster.
  • Loading branch information
kdy1 authored Jan 12, 2025
1 parent 7329824 commit 46e3d77
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions crates/swc_ecma_utils/src/parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,27 +86,23 @@ where
}

let (na, nb) = nodes.split_at(len / 2);
let mut vb = Parallel::create(&*self);

let (va, vb) = join(
let (_, vb) = join(
|| {
GLOBALS.set(globals, || {
let mut visitor = Parallel::create(&*self);
visitor.maybe_par_idx_raw(threshold, na, op);

visitor
self.maybe_par_idx_raw(threshold, na, op);
})
},
|| {
GLOBALS.set(globals, || {
let mut visitor = Parallel::create(&*self);
visitor.maybe_par_idx_raw(threshold, nb, op);
vb.maybe_par_idx_raw(threshold, nb, op);

visitor
vb
})
},
);

Parallel::merge(self, va);
Parallel::merge(self, vb);
});

Expand Down

0 comments on commit 46e3d77

Please sign in to comment.