Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont use workers for swc & esbuild minify #580

Open
ronakj opened this issue Oct 18, 2023 · 3 comments · May be fixed by #616
Open

Dont use workers for swc & esbuild minify #580

ronakj opened this issue Oct 18, 2023 · 3 comments · May be fixed by #616

Comments

@ronakj
Copy link

ronakj commented Oct 18, 2023

Modification Proposal

SWC and ESBuild minify both run off-thread though native bindings. We don't need to create workers to parallelize workloads for them, unlike terser or uglify-js which block the event loop if not run on separate worker. This should have performance improvement for people who have many output chunk files. I will try this out later and add some numbers to verify.

Expected Behavior / Situation

We simply use promise concurrenctly instead of workers to parallelize.

Actual Behavior / Situation

Workers are created regardless of minification implementation.

@alexander-akait
Copy link
Member

alexander-akait commented Dec 6, 2023

@ronakj Can you provide profiling? Because we use parallelization to compress multiple files and avoid memory problems with real big files

@kdy1
Copy link

kdy1 commented Jan 10, 2025

@alexander-akait

Will you accept a PR? SWC uses thread locals, and the worker thread causes segfaults on some platforms.

As a side note, next.js does not use workers for the SWC minifier because it's better for performance. I don't have the perf profile at the moment, but the parallelism of SWC is primarily managed by node.js worker threads (using napi), so it should be faster to call directly.

@kdy1
Copy link

kdy1 commented Jan 10, 2025

I tried, and using false in

enableWorkerThreads: true,
was enough to fix the issue.

swc-project/swc#9855 (comment)

@kdy1 kdy1 linked a pull request Jan 10, 2025 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants