Skip to content

Commit 46e3d77

Browse files
authoredJan 12, 2025··
perf(es/utils): Optimize maybe_par_idx_raw (#9870)
**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.
1 parent 7329824 commit 46e3d77

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed
 

‎crates/swc_ecma_utils/src/parallel.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -86,27 +86,23 @@ where
8686
}
8787

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

90-
let (va, vb) = join(
91+
let (_, vb) = join(
9192
|| {
9293
GLOBALS.set(globals, || {
93-
let mut visitor = Parallel::create(&*self);
94-
visitor.maybe_par_idx_raw(threshold, na, op);
95-
96-
visitor
94+
self.maybe_par_idx_raw(threshold, na, op);
9795
})
9896
},
9997
|| {
10098
GLOBALS.set(globals, || {
101-
let mut visitor = Parallel::create(&*self);
102-
visitor.maybe_par_idx_raw(threshold, nb, op);
99+
vb.maybe_par_idx_raw(threshold, nb, op);
103100

104-
visitor
101+
vb
105102
})
106103
},
107104
);
108105

109-
Parallel::merge(self, va);
110106
Parallel::merge(self, vb);
111107
});
112108

0 commit comments

Comments
 (0)
Please sign in to comment.