From 46e3d77396a9211ddd79c7390349053c857a9c76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Sun, 12 Jan 2025 18:24:37 +0900 Subject: [PATCH] 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. --- crates/swc_ecma_utils/src/parallel.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/crates/swc_ecma_utils/src/parallel.rs b/crates/swc_ecma_utils/src/parallel.rs index 68f9ba8a26de..1fadf4f8a4e9 100644 --- a/crates/swc_ecma_utils/src/parallel.rs +++ b/crates/swc_ecma_utils/src/parallel.rs @@ -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); });