Skip to content

Parse AST in worker#5211

Closed
lukastaegert wants to merge 3 commits intomasterfrom
parse-web-worker
Closed

Parse AST in worker#5211
lukastaegert wants to merge 3 commits intomasterfrom
parse-web-worker

Conversation

@lukastaegert
Copy link
Member

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:
cf. #5202

Description

This will move regular parsing into a worker thread. It would be interesting to compare this approach with #5202. The advantage of using a worker thread as opposed to native threads in Rust is that this approach also parallelizes the @rollup/wasm-node build.
As parsing is currently faster than analyzing and tree-shaking, I do not think it makes sense to use more than one additional thread. However, I set it up in a way so that we could easily switch to a worker pool with a configurable number of workers.
Originally, I wanted to use a singleton worker. However, then it became difficult to decide when to terminate the worker, as a running worker would prevent the process from completing. Instead, the worker will now terminate itself if inactive for one macro task tick. Another approach could have been to terminate the worker on build end. However in the long run, I hope to extend the plugin API to allow async parsing in generate hooks, in which case we would still need the worker.

@vercel
Copy link

vercel bot commented Oct 17, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
rollup ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 20, 2023 3:19pm

@lukastaegert lukastaegert marked this pull request as draft October 17, 2023 19:39
@github-actions
Copy link

github-actions bot commented Oct 17, 2023

Thank you for your contribution! ❤️

You can try out this pull request locally by installing Rollup via

npm install rollup/rollup#parse-web-worker

Notice: Ensure you have installed Rust nightly. If you haven't installed it yet, please first see https://www.rust-lang.org/tools/install to learn how to download Rustup and install Rust, then see https://rust-lang.github.io/rustup/concepts/channels.html to learn how to install Rust nightly.

or load it into the REPL:
https://rollup-asz8v50az-rollup-js.vercel.app/repl/?pr=5211

@codecov
Copy link

codecov bot commented Oct 17, 2023

Codecov Report

Attention: Patch coverage is 86.84211% with 5 lines in your changes missing coverage. Please review.

Project coverage is 98.76%. Comparing base (2bb2a64) to head (a509b7b).
Report is 537 commits behind head on master.

Current head a509b7b differs from pull request most recent head 265836d

Please upload reports for the commit 265836d to get more accurate results.

Files with missing lines Patch % Lines
src/utils/parseAstAsync.ts 83.33% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5211      +/-   ##
==========================================
- Coverage   98.82%   98.76%   -0.07%     
==========================================
  Files         231      233       +2     
  Lines        8849     8884      +35     
  Branches     2314     2319       +5     
==========================================
+ Hits         8745     8774      +29     
- Misses         43       49       +6     
  Partials       61       61              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jerome-benoit
Copy link
Contributor

worker_threads are not as efficient as native POSIX threads by design. Since the current use case is delightfully parallellisable, a unique native POSIX thread in rust with JS bindings and parsing task concurrency limit and a task FIFO will very likely out perform any worker_threads pool implementations available (I co-maintain one and be warned that: worker_threads communication are dead slow under load, worker_threads high memory usage needs tweaking to avoid OOM conditions, worker_threads startup time is quite slow compared to native POSIX thread, worker_threads memory sharing is way less convenient to work with than with native POSIX threads).

@lukastaegert
Copy link
Member Author

Yes, this confirms my observations at #5202 (comment), which is why I just merged and released @sapphi-red's approach #5202. This PR currently is mostly for reference and as inspiration if we want to parallelize the WASM builds after all.

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 this pull request may close these issues.

2 participants